为什么我得到 C2883:函数声明与 - 在仅覆盖基 class 的一个重载时由 using-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;
}
为什么下面的代码会出现编译错误?
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;
}