0
点赞
收藏
分享

微信扫一扫

拷贝构造函数浅拷贝(10)

小a草 2022-07-13 阅读 215


#ifndef
#define
#include <iostream>
using namespace std;
class A {
public:
int a;
int b;
void show();
A(A &c);
A();

};

#endif

#include "A.h"
A::A() {

this->a = 5;
this->b = 6;
cout << "A::A()" << endl;
}

A::A(A &a) {//浅拷贝
this->a = a.a;
this->b = a.b;
cout << "A::A(A &a)" << endl;

}

#include "A.h"
#include <iostream>
using namespace std;

void fun() {
A a1;
A a2 = a1;//拷贝构造函数,浅拷贝
cout << "a2.a = " << a2.a << " a2.b = " << a2.b << endl;
}


int main() {
fun();

}


举报

相关推荐

0 条评论