由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - C++ Q96: function inheritance (转载)
相关主题
两个看来相似的问题请问C++小白问题
[合集] 关于template和inheritance的问题请教Why oop is bad?
ask a C++ inheritance questionpublic and protected member in private inherit
C++ multiple inheritance probleminheritence problem
类设计问题求助请教一个class design的问题
How to check the virtual function table size?C++ (with MATLAB engine) compiling problem under Linux systerm
protected class member in C++关于c++ classes的interview test
问题:vptr/vtable for virtual function & vptr/vtable forone question about struct
相关话题的讨论汇总
话题: error话题: c++话题: q96话题: print话题: equals
进入Programming版参与讨论
1 (共1页)
c**********e
发帖数: 2007
1
【 以下文字转载自 JobHunting 讨论区 】
发信人: careerchange (Stupid), 信区: JobHunting
标 题: C++ Q96: function inheritance
发信站: BBS 未名空间站 (Sun Oct 16 11:50:54 2011, 美东)
Error information in the following code is Error: equals is not a member of
B.
My question: Why equals() is not a member of B but print() is?
While this seems obvious, what is the general rule that a function will be
inherited?
#include
using namespace std;
class A {
public:
bool equal(A a) { return true; }
void print() { cout << "print\n"; }
};
class B: public A {};
int main() {
B b;
bool x = b.equals(b);
b.print();
return 0;
}
X****r
发帖数: 3557
2
Get your question right first...

of

【在 c**********e 的大作中提到】
: 【 以下文字转载自 JobHunting 讨论区 】
: 发信人: careerchange (Stupid), 信区: JobHunting
: 标 题: C++ Q96: function inheritance
: 发信站: BBS 未名空间站 (Sun Oct 16 11:50:54 2011, 美东)
: Error information in the following code is Error: equals is not a member of
: B.
: My question: Why equals() is not a member of B but print() is?
: While this seems obvious, what is the general rule that a function will be
: inherited?
: #include

A**u
发帖数: 2458
3
typo equals-->equal
发包子吧
d****n
发帖数: 1637
4
好眼力,我还以为是什么深奥的问题

【在 A**u 的大作中提到】
: typo equals-->equal
: 发包子吧

c**********e
发帖数: 2007
5
Faint. I am stupid!
1 (共1页)
进入Programming版参与讨论
相关主题
one question about struct类设计问题求助
C++菜鸟问题请教: class versus structure.How to check the virtual function table size?
C++ cast 小结protected class member in C++
about multiple inheritance问题:vptr/vtable for virtual function & vptr/vtable for
两个看来相似的问题请问C++小白问题
[合集] 关于template和inheritance的问题请教Why oop is bad?
ask a C++ inheritance questionpublic and protected member in private inherit
C++ multiple inheritance probleminheritence problem
相关话题的讨论汇总
话题: error话题: c++话题: q96话题: print话题: equals