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 | |
|