Sign in to follow this  

Forward declaring classes within namespaces (c++)

This topic is 3379 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
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

This topic is 3379 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.

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