函数隐藏和重载之间的区别 [英] difference between function hiding and overloading
本文介绍了函数隐藏和重载之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我找不到函数隐藏和重载之间的任何区别.由于函数隐藏是存在于派生类中的函数,并且隐藏了基类的函数.它们在两个函数中具有相同的名称.重载:在派生类和基类中具有相同的名称,但签名不同.
I can't find any difference between function hiding and overloading. As the function hiding is the function that is present in derived class and hides the function of a base class. Having same name of the function in both of them. Overloading: having same name but different signature in both derived and base class.
class A {
void print(int);
};
class B: public A {
void print(float);
};
它是隐藏功能还是重载?
does it hide function or overload ?
推荐答案
函数 B :: print
隐藏父函数 A :: print 代码>.
如果要重载,则需要将 A :: print
函数拉入 B
的范围:
If you want to overload you need to pull in the A::print
function into the scope of B
:
class B : public A {
public:
using A::print; // Pull in (all) A::print symbols into the scope of B
void print(float); // Now overloads A::print
};
这篇关于函数隐藏和重载之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文