星星博客 »  > 

c++拷贝构造函数

#include <iostream>
using namespace std;

class TPoint
{
private:
    int x;
    int y;
public:
    TPoint(int X, int Y)
    {
        x = X;
        y = Y;
    }
    TPoint(TPoint& p)
    {
        x = p.x;
        y = p.y;
        cout << "拷贝了" << endl;
    }
    int GetX()
    {
        return x;
    }
    int GetY()
    {
        return y;
    }


};

int main()
{
    TPoint p1(10, 20);
    TPoint p2 = p1;
    return 0;
}

 

相关文章