c++ - Returning a typedef defined inside a non-type templated class -


i'm looking create non-type templated class member variables depend on non-type parameter (specifically, fixed-dimension eigen matrices, problem present int well). make things clearer typedef'ed member types, worked great until wanted member function return typedef @ point started getting following error:

myclass.cpp:10: error: expected constructor, destructor, or type conversion before ‘myclass’

i understand, conceptually @ least, has fact typedef depends on template , result c++ confused. problem i'm more confused, i've tried naive insertions of typename, didn't fix anything.

a minimum working example.

header:

template <int i> class myclass {   public:     typedef int myvector_t;      myclass();     myvector_t myfunc(); }; 

source code:

#include <myclass.hpp>  template <int i> myclass<i>::myclass() {   //blah }  template <int i> myclass<i>::myvector_t  myclass<i>::myfunc()        //<----- line 10 {   //blah } 

i'd appreciate insight.

edit: answer

as explained below solution include typename keyword in implementation, not declaration.

typename myclass<i>::myvector_t  myclass<i>::myfunc()        //<----- line 10 

edit2

generalized question away eigen

since name myvector_t in definition of function depends on template parameter, need let compiler know it's type typename:

template <int i> typename myclass<i>::myvector_t  myclass<i>::myfunc()        //<----- line 10 {   //blah } 

Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

php - joomla get content in onBeforeCompileHead function -