Eigen::Ref<> as a member variable
问题 I need a class to have an Eigen::Ref variable as a static member which would be initialized through an init static method. Something like this: class CostFunction { public: static Eigen::Ref<Eigen::VectorXd> data; static void init(const Eigen::Ref<Eigen::VectorXd>& d) { data = d; } CostFunction() {} }; int main() { Eigen::VectorXd data = Eigen::VectorXd::Random(30); CostFunction cf; cf.init(data); return 0; } This doesn't compile. I get an error which looks like this: /var/tmp/doNotRemove