#include <iostream>
using namespace std;
class temp
{
private:
char *a;
public:
temp(char c, char b)
{
a = new char[2];
a[0] = c;
a[1] = b;
cout << "3" << endl;
}
temp(temp &t):a(t.a)
{
a = new char[2];
cout << "2" << endl;
}
temp(temp &&t):a(t.a)
{
t.a = NULL;
cout << "1" << endl;
}
void show(void)
{
printf("%d", a[0]);
}
~temp() { cout << "析构" << endl; delete[] a; }
};
static temp get(void)
{
temp d(3, 4);
cout << "666" << endl;
return d;
}
int main(void)
{
temp c(1, 2), b = move(c);
c.show();
//temp d = get();
system("pause");
return 0;
}
上面构造函数不是开了空间吗?为什么会指向NULL?