![]() |
#2
tisyang2011-09-09 16:28
|

#include <iostream>
#include <stdlib.h>
using namespace std;
class Obj
{
public:
Obj(void)
{
cout<<"Initialization"<<endl;
}
~Obj(void)
{
cout<<"Destroy"<<endl;
}
void In(void)
{
cout<<"In"<<endl;
}
void Destroy(void)
{
cout<<"Destroy"<<endl;
}
};
void UseMallocFree(void)
{
Obj *a=(Obj *)malloc(sizeof(Obj));
a->In();
a->Destroy();
free(a);
}
void UseNewDelete(void)
{
Obj *a=new Obj;
delete a;
}
int main()
{
Obj obj; //
UseMallocFree();
UseNewDelete();
}
#include <stdlib.h>
using namespace std;
class Obj
{
public:
Obj(void)
{
cout<<"Initialization"<<endl;
}
~Obj(void)
{
cout<<"Destroy"<<endl;
}
void In(void)
{
cout<<"In"<<endl;
}
void Destroy(void)
{
cout<<"Destroy"<<endl;
}
};
void UseMallocFree(void)
{
Obj *a=(Obj *)malloc(sizeof(Obj));
a->In();
a->Destroy();
free(a);
}
void UseNewDelete(void)
{
Obj *a=new Obj;
delete a;
}
int main()
{
Obj obj; //
UseMallocFree();
UseNewDelete();
}