S**Y 发帖数: 136 | 1 question 1:
template
class Foo
{
T tVar;
public:
Foo(T t) : tVar(t) { }
};
class FooDerived : public Foo { };
FooDerived fd;
What is preventing the above code from being legal C++?
A. FooDerived is a non-template class that derives from a template class.
B. tVar is a variable of an unknown type.
C. A constructor must be provided in FooDerived.
D. FooDerived uses the non-C++ type std::string.
E. The initialization of tVar occurs outside the body of Foo's constructor.
=== | t****t 发帖数: 6806 | 2 the expected answer should be C and C, but the 2nd C is not exactly right.
you can call virtual functions in ctor/dtor, however they will not be
overrided in ctor/dtor, but they are treated as regular member functions. it
is implied the get_name() is not defined (being pure virtual), but actually
pure virtual member can also be defined.
See 12.7, clause 3
【在 S**Y 的大作中提到】 : question 1: : template : class Foo : { : T tVar; : public: : Foo(T t) : tVar(t) { } : }; : class FooDerived : public Foo { }; : FooDerived fd;
| S**Y 发帖数: 136 | 3 Thanks a lot thrust.
It is very clear now....
it
actually
【在 t****t 的大作中提到】 : the expected answer should be C and C, but the 2nd C is not exactly right. : you can call virtual functions in ctor/dtor, however they will not be : overrided in ctor/dtor, but they are treated as regular member functions. it : is implied the get_name() is not defined (being pure virtual), but actually : pure virtual member can also be defined. : See 12.7, clause 3
|
|