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

[SOLVED] Template int params not taken as const

Tags: None
(comma "," separated)
cbecker
Registered Member
Posts
2
Karma
0
Hi everyone. I've been using eigen2 for a while. Thanks to all the developers for making such a nice and fast library!

Now I'm facing a problem with a custom template I'm coding, here is a test case:
Code: Select all
#include
#include

USING_PART_OF_NAMESPACE_EIGEN

template
class MyTemplate
{
public:
   Matrix   m1;
   Matrix   m2;

   void   init()
   {
      m1.setIdentity();
      m2.setIdentity();
   }

   void   test()
   {
      m2.block(0,0) = m1.block(0,0);
   }
};

int main()
{
   MyTemplate   A;

   A.init();
   A.test();

   return 0;
}


I get an error when calling A.test(). It looks as if matrix size is not considered constant at compile time, so the block() funcs are not available. If I hard code M and N by using 'static const int' in MyTemplate then it works, but I lose template advantages.
Is there a way to solve this and 'convince' eigen that matrix size is known at compile time? Why would this be happening?

Thank you.

Last edited by ggael on Sat May 02, 2009 6:58 pm, edited 1 time in total.
User avatar
bjacob
Registered Member
Posts
658
Karma
3
I don't think that's the issue as the fixed-size block(c,d) method is available also for dynamic-size matrices.

I rather think you're hitting the old c++ syntax issue that you need to add a template keyword:

replace this line
Code: Select all
m2.block(0,0) = m1.block(0,0);


by
Code: Select all
m2.template block(0,0) = m1.template block(0,0);


Otherwise, can you tell us exactly what error you get?

Last edited by bjacob on Sat May 02, 2009 2:15 pm, edited 1 time in total.


Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list!
cbecker
Registered Member
Posts
2
Karma
0
Thanks bjacob, that did it! I'm starting with C++ templates, I will have to investigate further into the template keyword and see what it does when used as you did. Now it compiles fine.

Thanks!
User avatar
bjacob
Registered Member
Posts
658
Karma
3
All it does here is indicate that the next token is a templated method.

I know it's very strange, it's confusing everyone and you can see that another recent thread here was also another user having this same problem.


Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list!


Bookmarks



Who is online

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