[ create a new paste ] login | about

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

C++, pasted on Apr 25:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
class Base {
public:
    int data_;
    void bar() { std::cout << "Base\n"; }
};

class Derived : public Base {
public:
    void fun() { ::std::cout << "Hi, I'm " << this << ::std::endl; }
    virtual void bar() { std::cout << "Derived\n"; }
};

int main() {
    Base base;
    Derived *derived = static_cast<Derived*>(&base); // Undefined behavior!

    derived->fun(); 
    derived->bar();
    return 5;
}


Output:
1
2
3
Hi, I'm 0xbf6148b4

Segmentation fault


Create a new paste based on this one


Comments: