I am writing a generic class that utilizes Eigen data types. I already have problems assigning constructor arguments to class member variables. A simplified version of my code would be:
template <typename Derived>
class A
{
public:
Eigen::Matrix<Derived> M; // error C2976: too few template parameters
A(const Eigen::DenseBase<Derived> & V)
{
M = V.eval(); // I would want to snapshot the value of V.
}
};
My question is now what data type M
should be? I tried a variety of options, such as:
Eigen::internal::plain_matrix_type_column_major<Derived> M;
Eigen::DenseBase<Derived> M;
but they just generate different errors. Note that I use C++17 and expect the class template parameter to be inferred from the constructor.
Eigen::Matrix
appears to be correct type for you, then stay with, but find out what the other parameters are used for and apply them appropriately (hint: you might need further template parameters for your own class, too). – GossA
? What types canDerived
have? You could tryDerived::PlainObject
, if you want to store anyDerived
type in the corresponding plain type (this automatically derives the scalar type, dimensions, etc). – BuenabuenaventuraV
can have fixed, dynamic, or mixed sizes.M
is intended to just store the values ofV
, which is the reason for the.eval()
. In general,A
will compute new values based onV
but I need to keep the input and other intermediate results for later use. – AdapterA
? I guess you essentially want to writeA a{some_expression};
, right? – Buenabuenaventura