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 const |
|
h*****g 发帖数: 312 | 2 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 是正确的呢? |
|
S**Y 发帖数: 136 | 3 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.
=== |
|
C*******h 发帖数: 60 | 4 template
class Foo
{
T tVar;
public:
Foo(T t) : tVar(t) { }
};
class FooDerived : public Foo { };
FooDerived fd;
Why the code above NOT syntactically correct C++?
1) FooDerived uses the non-C++ type std::string.
2) FooDerived is a non-template class that derives from a template class.
3) The initialization of tVar occurs outside the body of Foo's constructor.
4)tVar is a variable of an unknown type.
5) A constructor must be provided in FooDerived.
从bb上看到的,谢谢! |
|
d****z 发帖数: 53 | 5
FooDerived has no proper constructor, needs to write one
constructor.
a
oper
destructor.
Since it's a pure virtual function, should not be called in the destructor
illega
no |
|
l******l 发帖数: 66 | 6 Because 'FooDerived fd;' needs default constructor. |
|
h*****g 发帖数: 312 | 7 默认的ctr 不是系统自动给FooDerived fd调用的吗?为啥还得写出来? |
|