ArthurSonzogni / FTXUI

:computer: C++ Functional Terminal User Interface. :heart:
MIT License
6.73k stars 401 forks source link

Can't convert pointers to StringRef #250

Closed arguiot closed 2 years ago

arguiot commented 2 years ago

I keep getting theses errors:


error: no matching function for call to 'Input'
                                Component input_first_name = Input(&first_name, "first name");
                                                                   ^~~~~
/build/_deps/ftxui-src/include/ftxui/component/component.hpp:34:11: note: candidate function not viable: no known conversion from 'std::string *' (aka 'basic_string<char> *') to 'ftxui::StringRef' for 1st argument
ArthurSonzogni commented 2 years ago

Hellow,

The StringRef adapter is declared as:

/// @brief An adapter. Own or reference a constant string. For convenience, this
/// class convert multiple mutable string toward a shared representation.
class StringRef {
 public:
  StringRef(std::string* ref) : address_(ref) {}
  StringRef(std::string ref) : owned_(std::move(ref)) {}
  StringRef(const wchar_t* ref) : StringRef(to_string(std::wstring(ref))) {}
  StringRef(const char* ref) : StringRef(std::string(ref)) {}
  std::string& operator*() { return address_ ? *address_ : owned_; }
  std::string* operator->() { return address_ ? address_ : &owned_; }

 private:
  std::string owned_;
  std::string* address_ = nullptr;
};

Since there is:

StringRef(std::string* ref)

I expect conversion from string* to work. I don't expect this error message. Could you provide instructions about how to reproduce this?

arguiot commented 2 years ago

Hmmm, not sure it's working... I just used the starter project, and replaced the content of main.cpp with your example, input.cpp. And I get this error. Very strange...

ArthurSonzogni commented 2 years ago

Can you copy the file you want to compile?

Le ven. 5 nov. 2021, 15:20, Arthur Guiot @.***> a écrit :

Hmmm, not sure it's working... I just used the starter project, and replaced the content of main.cpp with your example, input.cpp. And I get this error. Very strange...

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/ArthurSonzogni/FTXUI/issues/250#issuecomment-961934227, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABEJ4QUWQLYEQ32ECEEYJPDUKPY3DANCNFSM5HMKSMQQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

ArthurSonzogni commented 2 years ago

Closed. Does it still reproduce? If yes, please reopen and reply to https://github.com/ArthurSonzogni/FTXUI/issues/250#issuecomment-962009519