Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
函数重载对象hirearchy 在C++中,如果你有以下的 struct Base { }; struct Derived1 : Base { }; struct Derived2 : Derived1 { }; struct Derived3 : Derived2 { }; void f(const Derived2&) { std::cout << "Derived2" << std::endl; } void f(const Derived1&) { std::cout << "Derived1" << std::endl; } int main() { f(Derived3()); return 0; } struct Base { }; 结构Derived1:Base { }; 结构Derived2:Derived1 { }; 结构Derived3:Derived2 { }; 无效f(常数派生2&) { STD::CUT< P>引用的是C++ + < /P>_C++_Oop - Fatal编程技术网 引用的是C++ + < /P>,c++,oop,C++,Oop" /> 引用的是C++ + < /P>,c++,oop,C++,Oop" />

函数重载对象hirearchy 在C++中,如果你有以下的 struct Base { }; struct Derived1 : Base { }; struct Derived2 : Derived1 { }; struct Derived3 : Derived2 { }; void f(const Derived2&) { std::cout << "Derived2" << std::endl; } void f(const Derived1&) { std::cout << "Derived1" << std::endl; } int main() { f(Derived3()); return 0; } struct Base { }; 结构Derived1:Base { }; 结构Derived2:Derived1 { }; 结构Derived3:Derived2 { }; 无效f(常数派生2&) { STD::CUT< P>引用的是C++ + < /P>

函数重载对象hirearchy 在C++中,如果你有以下的 struct Base { }; struct Derived1 : Base { }; struct Derived2 : Derived1 { }; struct Derived3 : Derived2 { }; void f(const Derived2&) { std::cout << "Derived2" << std::endl; } void f(const Derived1&) { std::cout << "Derived1" << std::endl; } int main() { f(Derived3()); return 0; } struct Base { }; 结构Derived1:Base { }; 结构Derived2:Derived1 { }; 结构Derived3:Derived2 { }; 无效f(常数派生2&) { STD::CUT< P>引用的是C++ + < /P>,c++,oop,C++,Oop,在尝试解析要调用的函数时,如果参数类型中没有直接匹配,编译器必须对参数所需的转换进行排序,以便选择最佳候选 对于与继承层次结构中的对象相关的转换: 3) If Mid is derived (directly or indirectly) from Base, and Derived is derived (directly or indirectly) from Mid a) Derived* to Mid* is better than Derived* to Base* b) Derive

在尝试解析要调用的函数时,如果参数类型中没有直接匹配,编译器必须对参数所需的转换进行排序,以便选择最佳候选

对于与继承层次结构中的对象相关的转换:

3) If Mid is derived (directly or indirectly) from Base, and Derived is derived (directly or indirectly) from Mid
a) Derived* to Mid* is better than Derived* to Base*
b) Derived to Mid& is better than Derived to Base&
c) Base::* to Mid::* is better than Base::* to Derived::*
d) Derived to Mid is better than Derived to Base
e) Mid* to Base* is better than Derived* to Base*
f) Mid to Base& is better than Derived to Base&
g) Mid::* to Derived::* is better than Base::* to Derived::*
h) Mid to Base is better than Derived to Base

案例b)适用于您的示例。

谢谢,您能解释一下c)Base::*到Mid:*的含义吗?:*比Base:*到派生::*