After further reading, I found an answer:
According to the reference documentation of the matrix class, the first template parameter _Scalar
is:
_Scalar: matrix_tparam_scalar Numeric type, e.g. float, double, int or std::complex<float>.
User defined sclar types are supported as well.
It links to this page. It lists the requirements for the "custom scalar types". In the above example Eigen::NumTraits
for <Vector3d>
is missing. It can't be implemented properly for Vector3d
, so one should only store types that represent scalars inside an Eigen::Matrix
/Eigen::Array
.
Update:
The line without assignment n.transpose() * velField;
works because of lazy evalutation. It also works when doing this (in C++11):
auto result = n.transpose() * velField;
But it has done no calculation at that point (check the type of result
in the debugger). As soon as you use result
it will fail the same way than in your first example.