Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct foo {
- foo() {
- cout << "ctor" << endl;
- }
- ~foo() {
- cout << "dtor" << endl;
- }
- };
- int main() {
- foo foo_ {}; // "ctor" of foo_; stack allocation
- foo* bar = new foo {}; // "ctor" of bar; heap allocation
- foo* baz = new foo {}; // "ctor" of baz; heap allocation
- new (&foo_) foo {}; // "ctor" of foo_; placement new
- delete(bar); // "dtor" of bar; heap destruction
- ::operator delete(baz); // nothing; heap deallocation
- // "dtor" of foo_; stack destruction
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement