Advertisement Jump to content
Sign in to follow this  
luasitdown

access private variable by pointer or reference

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

class A
{

	int i;
};

class B
{
	A a;
public:
	A* aa(){return &a;}
};

B b;
			A *a1 = new A;
			a1 = b.aa();


I am surprise to I can access private by pointer or reference?? Is that true? why?

Share this post


Link to post
Share on other sites
Advertisement
What is surprising? You can always use dirty memory hacks to write anywhere in your process's memory space. So what? C++ allows you to call a public function, the public function is allowed to take the address of a private member and to pass it back, there is nothing wrong here (except your coding style).

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Eheh, "C++ est la vie", dude... ;)

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!