#include "stdafx.h"
#include
using namespace std;
#include
using namespace std;
class A{
public:
A();
A(int i);
int value;
int* p;};
public:
A();
A(int i);
int value;
int* p;};
A::A(){new(this)A(1);}//A::A(){ A(1);}错,在stack上建立了一个临时变量;
A::A(int i){
this->value=i;
this->p = NULL;
}
int _tmain(int argc, _TCHAR* argv[]){
A* ppp = new A();
return 0;
}
A::A(int i){
this->value=i;
this->p = NULL;
}
int _tmain(int argc, _TCHAR* argv[]){
A* ppp = new A();
return 0;
}
写多了C#的程序,突然间再回到古老的C++的确是非常不习惯。以上代码就今天解决的问题。感谢麦当!!~~强调一点,C++中是不直接支持ctor直接调用ctor的,除非有特殊需求才会出现以上特殊的语法。