double free or corruption

源代码

#include 
#include 
using namespace std;
class mystring
{
public:
	mystring ()
	{
		cout << "mystring构造"<
代码里的
	A(A &that)
	{
		cout << "A拷贝构造" << endl;
		c = new mystring;
		cout<< "旧的b:"<< c << endl;
		c = that.c;
		cout << "b:"<< c << "\n" << "a:"<< that.c << endl;		
				

}

c = that.c是相当于地址赋值给地址,应该改为*c = *that.c;

还有因为A的成员变量为类成员指针,当A构造或拷贝构造时是不分配内存,需要new一块内存给A的类成员存储数据;

即mystring *c是不分配内存.NULL也是不占内存,即mystring *c = NULL;也是不占空间的,需要new一块内存给它存储.

你可能感兴趣的:(double free or corruption)