What happens to a member variable in C++ if you don't define the access rights?
For instance, in the following code:
class Base {
int myQuestion;
public:
int myPublic;
private:
int myPrivate;
}
Who has access to myQuestion
?
What happens to a member variable in C++ if you don't define the access rights?
For instance, in the following code:
class Base {
int myQuestion;
public:
int myPublic;
private:
int myPrivate;
}
Who has access to myQuestion
?
If you use the keyword class
, access defaults to private
. If you use struct
it defaults to public
.
That's pretty much the only difference between the two keywords.
The only other difference is when you inherit, class
defaults to private inheritance, struct
to public inheritance.