c++ 对象数组简单的运用举例
程序员文章站
2022-07-15 08:39:31
...
#include<iostream>
using namespace std;
class Point{
public:
Point();
Point(int x,int y);
~Point();
void move(int newX,int newY);
int getX() const{return x;}
int getY() const{return y;}
static void showCount();
private:
int x,y;
};
Point::Point():x(0),y(0){
cout<<"Dwfault Constructor called."<<endl;
}
Point::Point(int x,int y):x(x),y(y){
cout << "Construor called."<<endl;
}
Point::~Point(){
cout <<"Destructor called."<<endl;
}
void Point::move(int newX,int newY){
cout<<"Moving the point to("<<newX<<","<<newY<<")"<<endl;
x = newX;
y = newY;
}
int main(){
Point A[2];
for(int i = 0;i <2;i++){
A[i].move(i + 10, i + 20);
}
return 0;
}
上一篇: Python3基础第九篇:字符串格式化
下一篇: 求两个数的最大公约数和最小公倍数