Jump to content
  • Advertisement
Sign in to follow this  
junkacc

Forward declaring classes within namespaces (c++)

This topic is 3593 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'm using Visual Studio 2008 (c++) and I have been trying to forward declare a class within in its own namespace into another class which has its own namespace too, with very little success. This is a sample of what I'm trying to do:
namespace name1
{
	class class1;
}


namespace name2
{
	class class2
	{
	public:
		name1::class1 c1;
	};
}


With this sample code I get the compiler error: error C2079: 'name2::class2::c1' uses undefined class 'name1::class1 Can anyone help me figure out how to do this please? Or even if it is possible to do this?

Share this post


Link to post
Share on other sites
Advertisement
You can't use a forward declaration here because class2 is trying to hold class1 by value. Try switching to a (smart) pointer or reference.

Share this post


Link to post
Share on other sites
I was afraid that would be the answer I guess I'll just have to include the header. Thanks for the fast reply, it is much appreciated.

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!