xcode - 为什么使用重载的虚拟函数给出'is hidden'警告
xcode - why is a warning of 'is hidden' given with overloaded virtual functions
我有一个基类,例如:
class A {
public:
virtual void methodA(int) {}
virtual void methodA(int, int, int) {}
};
xcode给出了methodA被隐藏的警告-一切似乎都如我所期望的那样工作(从A派生的类可以通过A指针访问,并使用methodA的任何一个)。
我猜从A
派生的一个类(假设它是B
)只覆盖methodA()
的一个重载。在这种情况下,methodA
的另一个过载是隐藏在B
中的。例子:
class A {
public:
virtual void methodA(int) {}
virtual void methodA(int, int, int) {}
};
class B : public A {
public:
virtual void methodA(int) {}
};
int main()
{
A a;
B b;
A *pa = &b;
a.methodA(7); //OK
a.methodA(7, 7, 7); //OK
pa->methodA(7); //OK, calls B's implementation
pa->methodA(7, 7, 7); //OK, calls A's implementation
b.methodA(7); //OK
b.methodA(7, 7, 7); //compile error - B's methodA only accepts one int, not three.
}
解决方案是在B
中添加using
声明:
class B : public A {
public:
using A::methodA; //bring all overloads of methodA into B's scope
virtual void methodA(int) {}
};
相关文章:
- 警告的原因是什么:"when type is in parentheses, array cannot have dynamic size"?
- 禁止显示"use of the 'X' attribute is a C++17 extension"警告
- q致命参数:将 QString 转换为常量字符* 会导致警告"format string is not a string literal"
- 使用代码调整删除"comparison is always false"警告
- 修复警告"field a is not used"如果字段在配置中未使用的好方法
- 特征"'__CUDACC_VER__' is not defined"警告
- 处理"Thrown exception type is not nothrow copy constructible"警告
- 当从此到子类中的新对象时,将显示警告"destination for this 'memcpy' call is a pointer to dynamic class..."
- 虚假"<function> is expected to return a value"警告?
- PTXAS 在结构数组上使用 thrust::sort 时"double is not supported"警告
- 检查布尔模板参数时摆脱"conditional expression is constant"警告的方法?
- 摆脱编译器警告"warning: result of call is not used"
- 消除警告"construction of local static object is not thread-safe"
- 如何抑制此内容 - qglobal.h:320:6: 警告: #warning "This version of Mac OS X is unsupported" ?
- GCC - 删除"is used uninitialized in this function"警告
- 如何避免模板代码中编译时常量条件"conditional expression is constant"警告?
- 错误"value computed is not used"警告
- 如何克服"'aclocal-1.15' is missing on your system"警告?
- 收到警告 C4189 "local variable is initialized but not referenced"即使正在引用变量
- 如何在Xcode 4中摆脱"In class initializer for static data member ... is a C++0x extension"警告