[ create a new paste ] login | about

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

C++, pasted on Jun 5:
#include <iostream>

using namespace std;

struct A { 
    virtual void f() {
        std::cout << "A:f() \n";
    }
    
};

struct B : virtual public A { 
    int i; 
};

struct C : virtual public A {
    int j; 
#if 1
    virtual void f() = 0; 
#endif    

#if 0
    virtual void f()  
    {
        std::cout << "C:f() \n";
    }
#endif    
};

struct D : public B, public C { 
#if 1
    virtual void f() {
        std::cout << "D:f() \n";
    }
#endif    
};

void f() {
    D d;
    C *volatile cp = &d;
    A *volatile ghost_ap = reinterpret_cast<A*> (cp);
    ghost_ap->f(); // use the vptr of C::A: safe?

}

int main()
{
    f();

   return 0;
}


Output:
1
D:f() 


Create a new paste based on this one


Comments: