由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 请教template class怎么处理Inheritance问题(面试题)
相关主题
uber 的一个面试题Python 如何自动import multiple files
inheritence problem
相关话题的讨论汇总
话题: class话题: template话题: baseclass话题: base
进入JobHunting版参与讨论
1 (共1页)
K******g
发帖数: 1870
1
今天面试被问到template class怎么处理Inheritance问题,我没有答上来,觉得
template class处理inheritance应该与普通的class没有什么区别。
放下电话后,在effective C++的item43里找到了,derived class cannot inherit
public functions from the base class, we need use this->, or using to use
public functions from the base class in the derived class.
但是,我写了个程序, derived class still can inherit public functions from
the base class.(用的是g++编译器)
请问C++的大牛们,到底哪个对啊?难道这种东西是compiler dependent的?
还有这个面试题应该怎么回答呢?多谢了
I*****y
发帖数: 602
2
template class本身和成员函数只有在调用的时候才被instantiation, 在你的main函
数里面调用一下你的derived class的成员看看。
template class即使本身逻辑有错,只要不被instantiation的话,编译器也不会报错
。编译器只看语法。

【在 K******g 的大作中提到】
: 今天面试被问到template class怎么处理Inheritance问题,我没有答上来,觉得
: template class处理inheritance应该与普通的class没有什么区别。
: 放下电话后,在effective C++的item43里找到了,derived class cannot inherit
: public functions from the base class, we need use this->, or using to use
: public functions from the base class in the derived class.
: 但是,我写了个程序, derived class still can inherit public functions from
: the base class.(用的是g++编译器)
: 请问C++的大牛们,到底哪个对啊?难道这种东西是compiler dependent的?
: 还有这个面试题应该怎么回答呢?多谢了

P*******e
发帖数: 65
3
If the function inherited from the base template class has paramters as the
type of the base template class, the "this->" can be avoided. Otherwise, "
this->" is necessary to tell the compiler the type used in the base template.
template
class BaseClass {
public:
BaseClass() {};
~BaseClass() {};
void Write(T var);
T Read(void);
private:
T variable;
};
template
class ChildClass : public BaseClass {
public:
ChildClass() {};
~ChildClass() {};
void WriteA

【在 K******g 的大作中提到】
: 今天面试被问到template class怎么处理Inheritance问题,我没有答上来,觉得
: template class处理inheritance应该与普通的class没有什么区别。
: 放下电话后,在effective C++的item43里找到了,derived class cannot inherit
: public functions from the base class, we need use this->, or using to use
: public functions from the base class in the derived class.
: 但是,我写了个程序, derived class still can inherit public functions from
: the base class.(用的是g++编译器)
: 请问C++的大牛们,到底哪个对啊?难道这种东西是compiler dependent的?
: 还有这个面试题应该怎么回答呢?多谢了

1 (共1页)
进入JobHunting版参与讨论
相关主题
uber 的一个面试题Python 如何自动import multiple files
inheritence problem
相关话题的讨论汇总
话题: class话题: template话题: baseclass话题: base