Jump to content
  • Advertisement
Sign in to follow this  
luasitdown

access private variable by pointer or reference

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

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!