[Solved] Problem with nested classes and templates

Started by
1 comment, last by Trenki 16 years, 10 months ago
Hi! I have a problem and cannot find out what is wrog.

template <class T>
template <class T>
struct Outer {
	struct Inner {
		typedef T Type;
	};
	
	virtual Inner::Type* tes1() = 0;
	Inner::Type test2() {}
};


With gcc 4.1.1 i get the following error message. I have not yet tried with VC.

problem.cpp:7: error: type 'Outer<T>::Inner' is not derived from type 'Outer<T>'
problem.cpp:7: error: expected ';' before '*' token
problem.cpp:8: error: expected ';' before 'test2'
problem.cpp:9: error: expected `;' before '}' token
Can you please tell me what I am doing wrong? Without the template eveything compiles fine but when I add it the compiler complains. [Edited by - Trenki on May 26, 2007 1:34:27 PM]
Advertisement
I believe that you need to specifically tell the compiler that Type is a type by using the typename keyword. This code compiles fine:

template <class T>struct Outer {  struct Inner {    typedef T Type;  };  virtual typename Inner::Type* tes1() = 0;  typename Inner::Type test2() {}};


You can read more about this in C++ FAQ Lite
Best regards, Omid
Hi and thanks! I just found out myself. Visual Studio gave me the hint.

This topic is closed to new replies.

Advertisement