This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Using Eigen in templates

Tags: None
(comma "," separated)
adamsz
Registered Member
Posts
1
Karma
0

Using Eigen in templates

Thu Nov 10, 2011 1:42 pm
Hi all,

compiling the code listed below fails with the following error:

Code: Select all
test.cpp: In function ‘void something()’:
test.cpp:16: error: expected primary-expression before ‘double’
test.cpp:16: error: expected ‘;’ before ‘double’


The commented out variant works fine. Any ideas what is wrong here?
Btw. this happens with GCC 4.3, 4.4 and with Eigen 2 and 3.

Code: Select all
#include <Eigen/Core>
#include <iostream>

struct X {
   enum {
      DIM = 3
   };
};

template <class T>
void something() {
   Eigen::Matrix<int,T::DIM,T::DIM> m;
   //Eigen::Matrix<int,3,3> m;

   m << 1,2,3,4,5,6,7,8,9;
   std::cout << m.cast<double>();
}

int main() {
   something<X>();

   return 0;
}


Best regards, Adam
jitseniesen
Registered Member
Posts
204
Karma
2

Re: Using Eigen in templates

Thu Nov 10, 2011 2:20 pm
You have to write "m.template cast<double>()". This is a rather obscure C++ feature; see http://eigen.tuxfamily.org/dox-devel/To ... yword.html for some explanation.


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]