如果我有
Class *a1 = new Class();
Class *b1 = a1;
delete b1;
delete a1; //this will give a double free or corruption message;
如果我删除指针b,它与删除指针a一样吗?由于两者都指向同一个 Class 实例。那么,如何将 a1 的实例复制到 b1,以便在删除 b1 时,不会删除 a1。
Class *a1 = new Class();
Class *b1 = a1;
//how do I duplicate the instance a1 is pointing
//so that when I delete b1, a1 still exists.
delete b1;
delete a1; //this is still valid
谢谢。