#include <iostream>//拷贝构造函数
using namespace std;
class CExample
{
private:
int a;
public:
CExample(int b) //构造函数
{
a = b;
cout<<"creat: "<<a<<endl;
}
CExample(const CExample& C)//拷贝构造
{
a = C.a;
cout<<"copy"<<endl;
}
~CExample()//析构函数
{
cout<< "delete: "<<a<<endl;
}
void Show ()
{
cout<<a<<endl;
}
};
//全局函数,传入的是对象
void g_Fun(CExample C)
{
cout<<"test"<<endl;
}
int main()
{
CExample test(1);
g_Fun(test);//传入对象
getchar();
return 0;
}
C++拷贝构造函数
最新推荐文章于 2024-08-17 18:54:27 发布