struct structure must have basic grammar are very familiar with, but in C ++, struct features not make good use of C ++
Now to introduce the class: class
In the class with the structure, we can control access to members , divided into three kinds:
public | Public access, free access to |
private | Private access, can only be a member of itself (no matter what access rights) access, can not inherit |
protected | Protected members, only through inheritance or friend visit |
There may have been some unfamiliar terms, do not worry placed first
Statement example:
. 1 class the EXAMPLE 2 { . 3 public : // public . 4 int publicdata = . 1 ; . 5 Private : // private . 6 int PrivateData = 0 ; . 7 protected : // protected . 8 int ProtectData = - . 1 ; . 9 } ; // the Attention! !!
If we write:
1 class EXAMPLE 2 { 3 int UnknownData=1; 4 private: 5 int PrivateData=0; 6 protected: 7 int ProtectData=-1; 8 };
Now UnknownData property is private , it is the structure of different places
Very important : the structure default is public, and the class is private by default
In fact, the class declaration and the large-diameter structure is the same, but see here still do not see where there is different, please wait for the next chapter