类用关键字class来定义,包含公共属性(public)及私密属性(private)。基本形式为:
class
{
public://外界可以直接访问或者调用
private://只允许本类内部访问
};
如下:
class point
{
public:
void setCoordinate(int x, int y)
{
xPos=x;
yPos=y;
}
void printCoordinate(x,y)
{
cout<< "x = " << xPos << endl;
cout<< "y = " << yPos << endl;
}
private:
int xPos;
int yPos;
};