为什么我得到 C2883:函数声明与 - 在仅覆盖基类中的一个重载时通过使用 - delcaration 引入
Why do I get C2883: function declaration conflicts with - introduced by using-delcaration when overriding only one overload from a base class?
为什么下面的代码给我一个编译器错误?
struct lol {
void foo(int hi) { }
void foo(lol x) { }
};
void funcit() {
struct duh : public lol {
using lol::foo;
void foo(lol x) { }
};
lol().foo(10);
lol().foo(lol());
duh().foo(10);
duh().foo(lol());
}
int main() {
funcit();
return 0;
}
我希望它能够编译,其中duh::foo
会调用lol::foo
- 仅覆盖其中一个重载。使用Visual Studio Express 2012,我收到此错误:
error C2883: 'funcit::duh::foo' : function declaration conflicts with 'lol::foo' introduced by using-declaration
代码是正确的,可以使用GCC 4.8.1进行编译。这似乎是 MSVC 2012 中的一个错误。将结构从函数中移除将导致其正常工作:
struct lol {
void foo(int hi) { }
void foo(lol x) { }
};
namespace {
struct duh : public lol {
using lol::foo;
void foo(lol x) { }
};
}
void funcit() {
lol().foo(10);
lol().foo(lol());
duh().foo(10);
duh().foo(lol());
}
int main() {
funcit();
return 0;
}
相关文章:
- 一个关于在C++中重载布尔运算符的问题
- 为什么我可以在不重载 "=" 运算符的情况下将一个对象分配给另一个对象?
- C++重载函数,一个采用基类的参数,另一个采用派生类的参数
- 我在 .h 中有一个枚举类,并且在.cpp错误中有一个运算符重载:与"运算符<<不匹配
- 运算符重载:"operator+"必须采用零个或一个参数
- 重载运算符*以获取对另一个类的实例的引用
- 我重载了 << 和 = 运算符。为什么当我将一个对象分配给另一个对象并尝试打印它时,我会被打印出来?
- MSVC 错误:4 个重载中的任何一个都无法转换所有参数类型
- 为什么我得到 C2883:函数声明与 - 在仅覆盖基类中的一个重载时通过使用 - delcaration 引入
- 尝试将节点插入链表中,但我需要一个重载运算符<函数
- 如果存在可以匹配另一个重载函数的函数模板,将调用哪个函数
- 根据可用的参数使用一个或另一个重载的创建者
- 重载运算符试图将另一个重载运算符作为参数
- 当涉及一个重载函数作为实参时,模板实参推导是如何工作的
- 我正在努力完成我的作业.在Distance类中创建一个重载*操作符
- 当派生类中存在另一个重载时,无法调用基类的方法
- C++ - 链接器找不到我的函数,它恰好是一个重载运算符
- 将类构造函数重载放在同一类的另一个重载中
- 可以在c++中调用另一个重载构造函数吗?
- 定义一个重载函数的类型