Sign in to follow this  

Private members in C++ headers

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

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this