Sign in to follow this  
Trenki

[Solved] Problem with nested classes and templates

Recommended Posts

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]

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this