C++ Quiz #2

posted in Washu's Journal
Published November 18, 2014
Advertisement

This is a test of your knowledge of C++, not of your compiler's knowledge of C++. Using a compiler during this test will likely give you the wrong answers, or at least incomplete ones.




  1. Using the code below as a reference, explain what behavior should be expected of each of the commented lines, please keep your answer very short.



    struct Base {
    virtual void Arr();
    };
    struct SubBase1 : virtual Base { };
    struct SubBase2 : virtual Base {
    SubBase2(Base*, SubBase1*);
    virtual void Arr();
    };


    struct Derived : SubBase1, SubBase2 {
    Derived() : SubBase2((SubBase1*)this, this) { }
    };
    SubBase2::SubBase2(Base* a, SubBase1* b) {
    typeid(*a); //1
    dynamic_cast<SubBase2*>(a); //2
    typeid(*b); //3
    dynamic_cast<SubBase1*>(b); //4
    a->Arr(); //5
    b->Arr(); //6
    }

  2. Using the code below as a reference, explain what behavior should be expected of each of the commented lines?



    template<class T> class X {
    X<T>* p; //1
    X<T> a; //2
    };



Source
0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement