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

private nested class friend functions

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!