[ The Types Forum, http://lists.seas.upenn.edu/mailman/listinfo/types-list ]

  Dear all,


I am formalizing a C++-like multiple inheritance model, please look at this 
piece of code:


//g++  5.4.0#include <iostream>class Deck {    public:        virtual void draw 
() { 
            std::cout << "Deck::draw" << std::endl; 
        }        virtual void shuffleAndDraw () { 
            std::cout << "Deck::shuffle" << std::endl; draw();        }};class 
LDeck : public Deck {    public: 
        virtual void draw () { 
            std::cout << "L::draw" << std::endl; 
        }};class Paint {    public: 
        virtual void draw () { 
            std::cout << "Paint::draw" << std::endl; 
        }};class Top : public LDeck, public Paint {};int main(){    Top b;    
Top *a = &b;    a->shuffleAndDraw();//shuffle and Ldraw    a->Deck::draw(); 
//draw    a->Paint::draw();//paint    ((Deck*)a)->draw();//LDraw    
((Paint*)a)->draw();//paint    return 0;}




For resolving the method call “ ((Deck*)a)->draw()”, C++ uses both the static 
(Deck) and dynamic(Top) type information of object a, so that the method call 
“draw()” dispatches to LDeck::draw(). 


I was wondering whether there are any formal models that describes this method 
lookup mechanism in C++. If anyone knows, could you please let me know? Thank 
you!


Best regards,
Yanlin Wang



Reply via email to