language: C++ 4.7.2 (gcc-4.7.2)
date: 420 days 22 hours ago
link:
visibility: public
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <iostream>
#include <memory>
#include <cstdlib>
 
struct test {
    int x;
    std::string s;
 
    void* operator new( std::size_t size) {
        char * p = (char*) malloc( size );
        for ( std::size_t i = 0; i < size; ++i ) {
            p[i] = 0xba;
        }
        return p;
    }
    void operator delete(void* p) {
        free(p);
    }
};
 
void f() {
    test t;
    std::cout << t.x << std::endl;
    t.x = 5;
}
 
void g() {
    test t = test();
    std::cout << t.x << std::endl;
    t.x = 5;
}
 
int main() {
    std::auto_ptr<test> p1( new test );
    std::cout << std::hex << p1->x << std::endl;
 
    std::auto_ptr<test> p2( new test() );
    std::cout << std::hex << p2->x << std::endl;
 
    f(); f();
    g(); g();
}