C++拷贝构造函数

来源:互联网 发布:布列斯特条约 知乎 编辑:程序博客网 时间:2024/06/08 00:40
#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;}

0 0
原创粉丝点击