欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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;
}