C++学习7 - 按别名传递对象

xiaoxiao2021-02-28  78

#include<iostream> using namespace std; class A{ public:  A(){ cout << "构造函数!" << endl; }  A(A&){ cout << "复制够造函数"<<endl; }  ~A(){cout<<"析构函数"<<endl; }  void set(int i){ x = i; }  int get()const{ return x; } private:  int x; }; A& fun(A &one){  return one; } int main(){  A a;  a.set(11);  A &b = fun(a);  cout << b.get();  return 0; }

更多详情请点击  http://blog.sina.com.cn/zhaojianjunzjj

 

转载请注明原文地址: https://www.6miu.com/read-74565.html

最新回复(0)