//1 重载一个new运算符,并传入一个对象地址返回这个对象地址
inline void* operator new(size_t, void* _Where)
{
return (_Where);
}
//2调用new
inline void* operator new(size_t, void* _Where)
{
return (_Where);
}
//2调用new
::new(ObjAddress) ClassName;
class CA
{
int xxx;
public:
CA()
{
xxx = 0;
printf("CA\n");
}
CA(int x)
{
xxx = x;
printf("CA(x)\n");
}
void dodo()
{
printf("x=%d\n", xxx);
}
public:
~CA()
{
printf("~CA\n");
}
};
int WINAPI WinMain(
HINSTANCE hinstance,
HINSTANCE hprevinstance,
LPSTR lpcmdline,
int ncmdshow)
{
if(AllocConsole())
{
freopen("CONOUT$", "w", stdout);
}
CA cca;
::new(&cca) CA(9);
cca.dodo();
cca.~CA();
return 0;
}