Below Code is equvalent:
- {
- A * a = new A;
- delete a;
- }
- {
- A * a = (A*)(::operator new(sizeof(A)));
- a->A::A();
- a->~A();
- ::operator delete(a);
- }
- #include <iostream>
- #include <list>
- #include <allocators>
- class A
- {
- public:
- A(){std::cout << " A()\n";}
- ~A(){std::cout << "~A()\n";}
- };
- int main()
- {
- using namespace std;
- {
- A * a = new A;
- delete a;
- }
- {
- A * a = (A*)(::operator new(sizeof(A)));
- a->A::A();
- if (a!=0)
- {
- a->~A();
- ::operator delete(a);
- }
- }
- return 0;
- }
沒有留言:
張貼留言