64,648
社区成员
发帖
与我相关
我的任务
分享
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <iostream>
#include <queue>
#include <map>
#include <vector>
using namespace std;
class class_int
{
public:
class_int()
{
t=new int [10];
}
~class_int()
{
delete [] t;
}
int *t;
};
class_int test()
{
class_int tmp;
tmp.t[1]=555;
return tmp;
}
int main()
{
class_int t6=test(); //此处按照我的 理解是 浅拷贝 因为 我没有写 拷贝构造函数
cout<<t6.t[1]; // 由于是浅拷贝,t6中的 t指针必然指向tmp中的数据内存,然而tmp作为临时变量,在上一句已经析构了
return 0; //因此输出应该是非法内存,但是VC中认为是非法内存,CB却认为是正常并且输出了555
}