lundi 19 février 2018

Eigen: Initializing Matrix to Identity does not compile

I have a template class B that derives from a template class A. Class A has 3 template parameters (the follow is A.h):

#ifndef A_HEADER
#define A_HEADER

#include "Eigen/Dense"

template<typename T = double, int xsize = Eigen::Dynamic, int ysize = Eigen::Dynamic>
class A {

public:
    // Constructor, etc.
    ...

which we derive from in class B:

#ifndef B_HEADER
#define B_HEADER

#include "A.h"
#include "Eigen/Dense"

template<typename T= double, int ysize = Eigen::Dynamic>
class B : public A<T, 4, ysize> {
private:

    Eigen::Matrix<T, ysize, 4> Hj = Eigen::Matrix<T, ysize, 4>::Identity(2, 4);

public:
    // Constructor, etc.
    ...

Then in the main function, I instantiate B like this:

 B<float> b(...

which I expect to pick up the template defaults. When I try to compile this in Cygwin G++, I don't get any compile errors. However, with Ubuntu G++, I am getting the errors

/mnt/c/Dropbox/drive/kf/src/b.h:11:68: error: declaration of ‘Eigen::Matrix<T, ysize, 4> B<T, ysize>::ysize’
     Eigen::Matrix<T, ysize, 4> Hj = Eigen::Matrix<T, ysize, 4>::Identity(2, 4);
                                                      ^
/mnt/c/Dropbox/drive/kf/src/b.h:7:38: error:  shadows template parm ‘int ysize’
 template<typename T = double, int ysize = -1>
                               ^
/mnt/c/Dropbox/drive/kf/src/b.h:11:75: error: expected unqualified-id before numeric constant
     Eigen::Matrix<T, ysize, 4> Hj = Eigen::Matrix<T, ysize, 4>::Identity(2, 4);
                                                             ^
/mnt/c/Dropbox/drive/kf/src/b.h:11:58: error: wrong number of template arguments (1, should be at least 3)
     Eigen::Matrix<T, ysize, 4> Hj = Eigen::Matrix<T, ysize, 4>::Identity(2, 4);
                                                   ^

What is the issue with this pattern?

Aucun commentaire:

Enregistrer un commentaire