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(a); //2
typeid(*b); //3
dynamic_cast(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 X {
X* p; //1
X a; //2
};
Comments (Close):1
Leave a Reply