您的位置:首页 > 编程语言 > C语言/C++

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

2016-02-22 11:08 330 查看
#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”: 对重载函数的调用不明确
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息