Jump to content
  • Advertisement
Sign in to follow this  
Tybon

Private members in C++ headers

This topic is 5127 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 have a n00b C++ question. I declare my class in a header file like this:
class MyClass {
private:
	int pVar;
};

Isn't it possible for someone to just change the private to public and my private variable is no longer private? How do I make sure that my private members stay private when I provide a header file with the class declaration to other programmers? Thank you.

Share this post


Link to post
Share on other sites
Advertisement
Access modifiers are there to protect against mistakes, not malicious abuse. If you give your source to someone else, they can always subvert it.

Share this post


Link to post
Share on other sites
They can modify it if they inherit your 'private' data. If someone wants to get a hold of it, there are ways to do it.

Share this post


Link to post
Share on other sites
Ok... thanks for the replies :) I am a Java programmer learning C++ right now. In Java, there are no header files. If another person wants to use my class, he/she just import it without knowing how my class is declared or if there are any private members at all. That's why I wanted to ask.

Share this post


Link to post
Share on other sites
Hmm... IIRC #defining keywords SHOULD be illegal according to the standard, but a quick test shows that at least gcc 3.4 lets it pass, even with strict settings. Is gcc defective, or do I remember incorrectly?

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!