Jump to content
  • Advertisement
Sign in to follow this  
Trenki

[Solved] Problem with nested classes and templates

This topic is 4072 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!