求专家解释------C++匿名对象
程序代码及结果如下:允许结果如何解释?
#include <iostream>using namespace std;#include <cstring>class A{ int data; char str[20];public: A():data(0){ cout << "A()" << "--" << this << endl; } A(int d):data(d){ cout << "A(" << d << ")" << "---"<< this << endl; strcpy(str,"qwe"); } ~A(){ cout << "~A()" << data <<"---" << this << "---" << str << endl; } void show(){ cout << "data=" << data <<"---"<< this << endl; }};int main(){ A a1(1); A(2); A(3).show(); cout << "========" << endl; A a4; a4 = A(4); }
A(1)---0x22cc20A(2)---0x22cc38~A()2---0x22cc38---qweA(3)---0x22cc50data=3---0x22cc50~A()3---0x22cc50---qwe========A()--0x22cc08A(4)---0x22cc68~A()4---0x22cc68---qwe~A()4---0x22cc08---qwe~A()1---0x22cc20---qwe