C++ 多重继承 函数重载 未搞清楚问题

来源:互联网 发布:淘宝卖家怎么怎么关闭 编辑:程序博客网 时间:2024/06/08 09:12
#include "stdafx.h"#include <iostream>using namespace std;class ZooAnimal { };class Bear : public ZooAnimal { };class Endangered { };class Panda : public Bear, public Endangered { };void print(const Bear&) { cout << __LINE__ << endl; }void print(const Endangered&) { cout << __LINE__ << endl; }void print(const ZooAnimal&) { cout << __LINE__ << endl; }void _tmain(int argc, _TCHAR* argv[]){  Panda ying_yang;  print(ying_yang);}

vc 2010 这样编译没有问题, 运行输出 13
如果 注释掉 15行,编译出错:error C2668: “print”: 对重载函数的调用不明确

如果 把 现在的第15行 移动到 第12行,,编译出错:error C2668: “print”: 对重载函数的调用不明确

0 1