[ create a new paste ] login | about

Link: http://codepad.org/cVMkdLxv    [ raw code | output | fork ]

C++, pasted on Mar 12:
#include <iostream>
using namespace std;

class A{
private:
    int num;
public:
    A(){
        cout << "A's constructor" << endl;
    }

    ~A(){
        cout << "~A" << endl;
    }
    void show(){
        cout << "num:" << num << endl;
    }
};

int main()
{
    char mem[10];
    mem[0] = 'a';
    mem[1] = '\0';
    mem[2] = '\0';
    mem[3] = '\0';
    cout << (void*)mem << endl;
    new(mem) char('b');
    A* p = new(mem) A;
    p->show();
    cout << p << endl;
    cout << (void*)mem << endl;
cout << mem[0];
    return 0;
}


Output:
1
2
3
4
5
6
0xffea491e
A's constructor
num:98
0xffea491e
0xffea491e
b


Create a new paste based on this one


Comments: