jeudi 31 octobre 2019

Why can't I inherit from Eigen::Matrix?

I have this class:

template < unsigned N, typename T >
class MY_EXPORT my_point : protected Eigen::Matrix< T, N, 1 >
{
public:
  using vector_type = Eigen::Matrix< T, N, 1 >;

  my_point() : vector_type{ vector_type::Zero() } {}
  using vector_type::vector_type;
};

My Linux (GCC) build is fine. However, on Windows (MSVC 15.9.16), I get really strange errors:

c:\include\eigen3\eigen\src\core\densebase.h(482): error C2338: THIS_METHOD_IS_ONLY_FOR_1x1_EXPRESSIONS (compiling source file c:\code\my_point.cxx) [C:\workspace\KwiverWindows\build\vital\vital.vcxproj]
  c:\include\eigen3\eigen\src\core\densebase.h(481): note: while compiling class template member function 'const float &Eigen::DenseBase<Derived>::value(void) const'
          with
          [
              Derived=Eigen::Matrix<float,4,1,0,4,1>
          ] (compiling source file c:\code\my_point.cxx)
  c:\include\eigen3\eigen\src\core\matrixbase.h(50): note: see reference to class template instantiation 'Eigen::DenseBase<Derived>' being compiled
          with
          [
              Derived=Eigen::Matrix<float,4,1,0,4,1>
          ] (compiling source file c:\code\my_point.cxx)
  c:\include\eigen3\eigen\src\core\plainobjectbase.h(100): note: see reference to class template instantiation 'Eigen::MatrixBase<Derived>' being compiled
          with
          [
              Derived=Eigen::Matrix<float,4,1,0,4,1>
          ] (compiling source file c:\code\my_point.cxx)
  c:\include\eigen3\eigen\src\core\matrix.h(180): note: see reference to class template instantiation 'Eigen::PlainObjectBase<Eigen::Matrix<float,4,1,0,4,1>>' being compiled (compiling source file c:\code\my_point.cxx)

It looks like the compiler is trying to instantiate inappropriate methods (e.g. a later error is trying to instantiate w() for a 3-vector). What am I doing wrong? (Why is this not a problem when using Eigen::Matrix directly?)

Here is a live demo.

Aucun commentaire:

Enregistrer un commentaire