0
点赞
收藏
分享

微信扫一扫

自考新教材-p174_4(1)

胡桑_b06e 2022-06-08 阅读 198

源程序:

#include <iostream>
using namespace std;

class pointer
{
public:
int a;
int *p;
pointer()
{
a = 100;
p = new int(10);
}
pointer(const pointer &tempp)
{
if (this != &tempp)
{
a = tempp.a;
p = tempp.p;
}
}
};

int main()
{
pointer p1;
pointer p2(p1);
cout << p1.a << ",\t" << *p1.p << ",\t" << (p1.p == p2.p) << endl;
*p1.p = 20;
p2.a = 300;
cout << (p1.a == p2.a) << ",\t" << *p1.p << ",\t" << (p1.p == p2.p) << endl;
system("pause");
return 1;
}

运行结果:

自考新教材-p174_4(1)_#include

 


举报

相关推荐

0 条评论