In my C++ code, I am getting the following error: no suitable user-defined conversion…
- User
In my C++ code, I am getting the following error: no suitable user-defined conversion from "lambda ->" to "StateFactory::CreateFunc" (aka "std::function<std::unique_ptr<State, std::default_delete> (std::shared_ptr)>") exists and this one: function returning function is not allowed Here the relevant method: Inside StateRegistrator, I am getting these errors: StateFactory::instance().registerState("BaseState", = -> std::unique_ptr(std::shared_ptr) { return std::make_unique(fullConfig); }); Inside StateFactory: using CreateFunc = std::function<std::unique_ptr(std::shared_ptr)>; void registerState(const std::string &name, CreateFunc func) { if (auto it = creators.find(name); it == creators.end()) { creators[name] = func; return; } throw std::invalid_argument("State already registered: " + name); }
codestd::unique_ptr<State> create(const std::string &name) const { if (!linked) throw std::invalid_argument("Configuration not linked"); if (auto it = creators.find(name); it != creators.end()) { return it->second(fullConfig); } throw std::invalid_argument("State not found: " + name); } void linkConfiguration(std::shared_ptr<IFullConfiguration> fullConfig_) { if (linked) throw std::invalid_argument("Configuration already linked"); fullConfig = fullConfig_; if (!fullConfig) throw std::invalid_argument("Invalid or undefined state"); linked = true; }State is the base class, BaseState the derived class.
- Assistant
The errors you are encountering in your C++ code result from a mismatch between the lambda function's signature and the signature expected by . Let's break down the issues and how to resolve them:
- User
Thank you.
- Assistant
You're welcome! If you have any more questions or need further clarification, feel free to ask. Happy coding!