c++ 複製建構函式示例程式
阿新 • • 發佈:2019-01-26
/*******************************************************
*author:彭曉林
*copyright: 版權所有,翻版不究
*function: 複製建構函式測試程式
******************************************************/
#include <iostream>
#include <string>
using namespace std;
class DEMO
{
public:
DEMO(int a, int b)
{
x = a;
y = b;
}
DEMO(DEMO &demo)
{
x = demo.x;
y = demo.y;
cout<<"複製建構函式被呼叫"<<endl;
}
void print();
private:
int x;
int y;
};
void DEMO::print()
{
cout<<x<<endl;
cout<<y<<endl;
}
int main()
{
DEMO TestA(1,2);
TestA.print();
cout<<endl;
DEMO TestB(TestA);
TestB.print();
while(1);
}s