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

Eigen cast

Tags: None
(comma "," separated)
User avatar
Spiros
Registered Member
Posts
25
Karma
1
OS

Eigen cast

Sat Jul 25, 2009 12:28 am
I don't understand how to operate the Matrix::cast() method.

In a test I wrote:
Code: Select all
//m0 is an object of Matrix4d
Matrix4i m1 = m0.cast<int>();


to cast a matrix of doubles in a matrix of ints and it compiled and executed prefectly.

In another test I have a class which stores a const reference to a Matrix (m0) and I must cast this matrix in a matrix of a specific type (m1). Consider the following code:
Code: Select all
template <typename MatrixType> class C
{
    typedef typename NumTraits<typename MatrixType::Scalar>::FloatingPoint Scalar;
    typedef Matrix<Scalar, MatrixType::RowsAtCompileTime, MatrixType::ColsAtCompileTime> MatrixNewType;
   
public:
    C(const MatrixType& _m) : m0(_m) { }
    void method() { m1 = m0.cast<Scalar>(); }
   
private:
    const MatrixType& m0;
    MatrixNewType m1;
};


The error I become from the compiler is:
Code: Select all
eigen_cast.cpp: In member function ‘void C<MatrixType>::method()’:
eigen_cast.cpp:15: error: expected primary-expression before ‘>’ token
eigen_cast.cpp:15: error: expected primary-expression before ‘)’ token


Why does the cast work good in normal cases but not compile if this is used within a class?

Last edited by Spiros on Mon Dec 14, 2009 1:46 pm, edited 2 times in total.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: Eigen cast  Topic is solved

Sat Jul 25, 2009 10:05 am
since cast is a template member function, in template code you have to prefix it with the template keywords:

m1 = m0.template cast<Scalar>();
User avatar
Spiros
Registered Member
Posts
25
Karma
1
OS

Re: Eigen cast

Sun Jul 26, 2009 11:50 am
ggael wrote:since cast is a template member function, in template code you have to prefix it with the template keywords:

m1 = m0.template cast<Scalar>();


Thank you very much!


Bookmarks



Who is online

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