实验报告

来源:互联网 发布:重庆网络推广公司排名 编辑:程序博客网 时间:2024/04/27 18:59

#include <iostream>

using namespace std;

class Point

{

public:

    Point()

    {

        x = 0;

        y = 0;

    }

    Point(int k, int l)

    {

        x = k;

        y = l;

    }

    void display()

    {

        cout << "(" << x << "," << y << ")" << endl;

    }

private:

    int x, y;

};

int main()

{

    Point t1;//无参构造函数定义对象的时候不用加括号。

    t1.display();

    int a, b;

    cin >> a >> b;

    Point t2(a, b);

    t2.display();

    return 0;

}

 

 

 

 

 

 

 

 

 

 

 

 

 

#include <iostream>

using namespace std;

class point

{

public:

    point()

    {

        cout << "Constructing an object of A" << endl;

    }

    ~point()//析构函数的调用要加“~”,是后进先出原则。

    {

        cout << "Destructing an object of A" << endl;

    }

};

int main()

{

    point t1, t2;

    return 0;

}

实验报告

原创粉丝点击