我在一个正在研究的课堂上使用Eigen。 代码摘录如下:
class model { public: Eigen::MatrixXd Ac; model (vars &, std::function<Eigen::MatrixXd()>, std::function<Eigen::MatrixXd()>); }; model::model (vars & vars, std::function<Eigen::MatrixXd()> muX, std::function<Eigen::MatrixXd()> muX2) //update Ac Ac = muX(vars) + muX2(vars); };我们的想法是,在创建model对象时,用户必须提供muX和muX2函数,类将使用muX和muX2填充MatrixXd Ac中的值。 vars只是一个由我创建的多个变量组成的类,而muX和muX2应该使用vars的数据作为输入。
但是,在我的XCode中,它给了我一个错误说:“没有匹配函数来调用`std :: function类型的对象”。 我还没有编译,但我认为编译器会给我同样的错误。
I'm using Eigen in a class that I'm working on. Here's the code excerpt:
class model { public: Eigen::MatrixXd Ac; model (vars &, std::function<Eigen::MatrixXd()>, std::function<Eigen::MatrixXd()>); }; model::model (vars & vars, std::function<Eigen::MatrixXd()> muX, std::function<Eigen::MatrixXd()> muX2) //update Ac Ac = muX(vars) + muX2(vars); };The idea is that when creating an object of model, the user will have to supply the functions muX and muX2, and the class will fill in values in MatrixXd Ac using muX and muX2. vars is just a class consisting of multiple variables that I created, and muX and muX2 are expected to use the data in vars as input.
However, in my XCode, it's giving me an error saying: "No matching function for call to object of type `std::function". I haven't compiled yet but I think the compiler will give me the same error.
最满意答案
std::function<Eigen::MatrixXd()>意味着它接受一个不接受任何参数的函数并返回一个Eigen::MatrixXd ,我认为这不是你想要做的。 您可能想将其更改为std::function<Eigen::MatrixXd(vars&)>
std::function<Eigen::MatrixXd()> implies that it takes a function which accepts no arguments and returns an Eigen::MatrixXd, which I think is not what you want to do. You probably want to change it to std::function<Eigen::MatrixXd(vars&)>
更多推荐
发布评论