Question 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(a); //2 typeid(*b); //3 dynamic_cast(b); //4 a->Arr(); //5 b->Arr(); //6}
Question 2:
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.
template class X { X* p; //1 X a; //2};
- 1. a is a pointer to a Base object
- 2. a is now casted to a SubBase2 object pointer
- 3. b is a pointer to a SubBase1 object
- 4. b fails because SubBase2 isn't derived from SubBase1
- 5. calls SubBase2::Arr()
- 6. calls Base::Arr()
2)
- 1. the variable p would be a pointer to a type T
- 2. the variable a would be a generic pointer so that container can hold the T class and derived classes(?)
And I know i got none of them right :(
EDIT: I used MSDN (not that it helped much).