I'm trying to write a class with a member fuction that returns an object of a type that's defined in one of the parameters.
Something like this:
Code:
class J
{
public:
template<typename T>
typename T::name op(const T& o)
{
return T::name();
}
};
T in this case would be an object of this class:
Code:
template<typename T>
class TI
{
public:
typedef T name;
};
with any random class used as the template parameter of TI
I'm using this:
when I try to use it like this
Code:
#include "ideas2.h" // that's where the class definitions are
int main()
{
/* other stuff I'm trying (currently commented out) removed */
J j1;
TI<I> ti1;
j1.op(ti1);
return 0;
}
gcc gives the following errors:
Code:
ideas2.h: In member function 'typename T::name J::op(const T&) [with T = TI<I>]':
test.cpp:36: instantiated from here
ideas2.h:20: error: dependent-name 'T::name' is parsed as a non-type, but instantiation yields a type
ideas2.h:20: note: say 'typename T::name' if a type is meant
gcc says to use typename, but I'm already using it and if I remove it it says this instead:
Code:
ideas2.h:18: error: expected constructor, destructor, or type conversion before 'op'
test.cpp: In function 'int main()':
test.cpp:36: error: 'class J' has no member named 'op'
Any ideas?