由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - C++ online Test 一题
相关主题
what is the problem with the following code examples?一道STL面试题
问个构造函数的问题C++ Singleton Template - 编译通不过
One C++ question问个C++模板定义的问题
C++ Q47: protected constructor (C39)问一道C++ template的面试题
今早google电面报告请教个C++的基础问题
c++ class default functions?A question about C++. Thanks.
【我自己写的LinkedList为什么总有错?】(回忆了几道题)有人做过 select2perfrom 的test吗 ?
问个C++ ctor的问题包子呼唤大牛--问关于C++Destructor的问题 (转载)
相关话题的讨论汇总
话题: fooderived话题: foo话题: tvar话题: class话题: c++
进入JobHunting版参与讨论
1 (共1页)
h*****g
发帖数: 312
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.
The initialization of tVar occurs outside the body of Foo's constructor.
B.
FooDerived uses the non-C++ type std::string.
C.
tVar is a variable of an unknown type.
D.
FooDerived is a non-template class that derives from a template class.
E.
A constructor must be provided in FooDerived.
为啥E 是正确的呢?
l******l
发帖数: 66
2
Because 'FooDerived fd;' needs default constructor.
h*****g
发帖数: 312
3
默认的ctr 不是系统自动给FooDerived fd调用的吗?为啥还得写出来?
l******l
发帖数: 66
4
Because base class already has a ctr, so no system generted ctr.

【在 h*****g 的大作中提到】
: 默认的ctr 不是系统自动给FooDerived fd调用的吗?为啥还得写出来?
d*****d
发帖数: 46
5
Because the base class's ctor is not a default ctor.

【在 l******l 的大作中提到】
: Because base class already has a ctr, so no system generted ctr.
f****4
发帖数: 1359
6
class A{
public:
A(int){}
};
class B: public A{
public:
B():A(0){}
};
h*****g
发帖数: 312
7
哦,因为子类对象创建时 先要调用基类default构造函数,但因为default 被omit了,
所以会出错。
谢谢各位~~~

【在 f****4 的大作中提到】
: class A{
: public:
: A(int){}
: };
: class B: public A{
: public:
: B():A(0){}
: };

h*****g
发帖数: 312
8
那如果在baseclass 自己写一个default ctr 也应该解决问题了吧?

【在 h*****g 的大作中提到】
: 哦,因为子类对象创建时 先要调用基类default构造函数,但因为default 被omit了,
: 所以会出错。
: 谢谢各位~~~

1 (共1页)
进入JobHunting版参与讨论
相关主题
包子呼唤大牛--问关于C++Destructor的问题 (转载)今早google电面报告
One C++ questionc++ class default functions?
C++ Q60 calling virtual function in constructor (JPMorgan)【我自己写的LinkedList为什么总有错?】
C++ online Test 一题问个C++ ctor的问题
what is the problem with the following code examples?一道STL面试题
问个构造函数的问题C++ Singleton Template - 编译通不过
One C++ question问个C++模板定义的问题
C++ Q47: protected constructor (C39)问一道C++ template的面试题
相关话题的讨论汇总
话题: fooderived话题: foo话题: tvar话题: class话题: c++