由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - find bugs of c++ codes
相关主题
问一个C++的问题问个copy constructor的问题
pointer to base class = new derived, what will happend??template 类的继承问题
一道c++的考古题What does the default constructor do?
急问:compile and build dependencyC++ 中 myobject * a =new myobject[n] 的问题
C++的一个小疑问,求解惑问一个 copy constructor 的问题 (C++)
vector在constructor里初始化c++ question
我这个C++程序有没有什么问题啊?请指点。。。谢谢。。。问个 ctor/copy ctor的问题
c++ initialize structone question about operator delete
相关话题的讨论汇总
话题: fooderived话题: foo话题: tvar话题: c++话题: class
进入Programming版参与讨论
1 (共1页)
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

1 (共1页)
进入Programming版参与讨论
相关主题
one question about operator deleteC++的一个小疑问,求解惑
请问关于c++实现singleton的问题?vector在constructor里初始化
C++ 书推荐我这个C++程序有没有什么问题啊?请指点。。。谢谢。。。
没有经过构造函数???c++ initialize struct
问一个C++的问题问个copy constructor的问题
pointer to base class = new derived, what will happend??template 类的继承问题
一道c++的考古题What does the default constructor do?
急问:compile and build dependencyC++ 中 myobject * a =new myobject[n] 的问题
相关话题的讨论汇总
话题: fooderived话题: foo话题: tvar话题: c++话题: class