您的位置:首页 > 编程语言 > C语言/C++

(C/C++学习笔记)Copy构造函数应用场景

2015-08-07 09:55 369 查看

Copy构造函数应用场景

#include"iostream"
using namespace std;

class Location
{
private:
int X,Y;
public:

Location(int xx = 0 , int yy = 0)
{
X = xx;
Y = yy;
cout << "Constructor Object . \n";
}
Location(const Location &p)
{
X = p.x;
Y = p.y;
cout << "Copy_constructor called ."<< endl;
}
~Location()
{
cout << X << "," << Y << " Object destroyed. "<< endl;
}
int GetX()
{
return X;
}

int GetY()
{
return Y;
}
};

void f (Location p)
{
cout << "Function:" << p.Getx() << "," << p.GetY() << endl;

}

void playobjmain()
{
Location A(1,2);
f(A);
}

int main(int argc, char const *argv[])
{
playobjmain();
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: