Members of a class acquire access attributes either by default (depending on class key and declaration placement) or by the use of one of the three access specifiers: public, private, and protected. The significance of these attributes is as follows:
Members of a struct are public by default, but you can override this with the private or protected access specifier.
Members of a union are public by default; this cannot be changed. All three access specifiers are illegal with union members.
A default or overriding access modifier remains effective for all subsequent member declarations until a different access modifier is encountered. For example,
class X { int i; // X::i is private by default char ch; // so is X::ch public: int j; // next two are public int k; protected: int l; // X::l is protected }; struct Y { int i; // Y::i is public by default private: int j; // Y::j is private public: int k; // Y::k is public }; union Z { int i; // public by default; no other choice double d; };
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
|
What do you think about this topic? Send feedback!
|