Jump to content
  • Advertisement
Sign in to follow this  
Nathaniel Hammen

private nested class friend functions

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

With this code:
class Class
{
	class NestedClass
	{
		private:
			Class* This;
			Class* That;
			void Func();

		public:
			friend void FriendFunc(NestedClass* &);
	};

//Other Stuff
};

void FriendFunc(Class::NestedClass* &NestedObjectPtr)
{
	NestedObjectPtr->Func();
}
It says "cannot access private class declared in class 'Class'" The only way that I can define FriendFunc is like this:
class Class
{
	class NestedClass
	{
		private:
			Class* This;
			Class* That;
			void Func();

		public:
			friend void FriendFunc(NestedClass* &NestedObjectPtr);
			{
				NestedObjectPtr->Func();
			}
	};

//Other Stuff
};
With large functions, this looks ugly. Is there a way to do this?

Share this post


Link to post
Share on other sites
Advertisement
class Class
{
class NestedClass
{
private:
Class* This;
Class* That;
void Func();

public:
friend void FriendFunc(NestedClass* &);
};

//Other Stuff
public:
friend void FriendFunc(NestedClass* &);

};

Share this post


Link to post
Share on other sites
FriendFunc can't access Class::NestedClass because it has private visibility. You need to declare NestedClass as public or declare FriendFunc as a friend of Class also.

Share this post


Link to post
Share on other sites
Well i guess this is kinda out of topic.. but isnt just easier to declare the function in other place and then use it in the class???

or... what's the deal about using Nested classes? whats the good thing about it??

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!