为什么下面的代码会给我一个编译器错误?
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 -仅覆盖重载之一。使用2012,我得到以下错误:
error C2883: 'funcit::duh::foo' : function declaration conflicts with 'lol::foo' introduced by using-declaration发布于 2015-04-16 00:17:08
代码是正确的,用GCC 4.8.1编写。这似乎是MSVC 2012中的一个bug。将结构从函数中删除将使其正常工作:
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;
}https://stackoverflow.com/questions/29663209
复制相似问题