Green_Hand_in_IT
南洋布衣
2017-10-09 10:16

为什么这样的调用会调用到父类中的函数?

  • class

#include
using namespace std;

class Ca{
public:
void do_down(void)
{
cout << "Ca down" << endl;
}
};

class Cb : public Ca
{
public:
void do_down(void)

{
cout << "Cb down" << endl;
}
};

class Cc : public Ca
{
public:
void do_down(void)

{
cout << "Cc down" << endl;
}
};

int main(void)
{
Ca *a1;

Cb b1;
a1 = &b1;
a1->do_down();

Cc c1;
a1 = &c1;
a1->do_down();

}
请教为什么编译运行后的结果是两个Ca down,而不是Cb down跟Cc down呢?

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

0条回答