菜鸟的博客

纵有疾风起,人生不言弃。

导航

2023.5.12

//例6-17
#include <iostream>
using namespace std;
class Point
{
public:
    Point() :x(0), y(0)
    {
        cout << "Default Constructor called." << endl;
    }
    Point(int x, int y) :x(x), y(y)
    {
        cout << "Constructor called." << endl;
    }
    ~Point()
    {
        cout << "Destructor called." << endl;
    }
    int getX() const { return x; }
    int getY() const { return y; }
    void move(int newX, int newY)
    {
        x = newX;
        y = newY;
    }
private:
    int x, y;
};
void test01()
{
    Point* ptr = new Point[2];
    ptr[0].move(5, 10);
    ptr[1].move(15, 20);
    cout << "Deleting..." << endl;
    delete[] ptr;
}
int main()
{
    test01();
    return 0;
}

 

posted on 2023-05-13 00:24  hhmzd233  阅读(20)  评论(0)    收藏  举报