類定義:
class Coordinate
{
public:
?int x;
?int y;
?void printX(){
?? cout<<x<<endl;
?}
? void printY(){
??cout<<y<<endl;
? }
}
類實例化對象:從棧中實例化,從堆中實例化。
int main(){
Coordinate cood;//棧實例化
cood.x=10;
cood.y=20;
cood.printX();
cood.printY();
Coordinate *cood=new Coordinate();//堆實例化
if(cood!=null){
cood->x=10;
cood->y=20;
cood->printX();
cood->printY();
}
system("pause");
}
訪問限定符:
public 公有的
protected 受保護的
private 私有的