考虑一个b类,使用两个重载的foo方法:
- struct b {
- void foo(float) {}
- void foo(const char *) {}
- };
如果我从b私下导出,我可以use using
to expose b
‘s foo
:
- struct d : private b {
- using b::foo;
- };
但是,这会暴露所有的重载.有没有办法露出其中一个(比如说浮动的)?例如,在下面我想最后一行编译失败:
- d t;
- t.foo(3.13); // d should have this overload
- t.foo("hello"); // d shouldn't have this overload
我尝试过各种写作方式
- using b::<i mean only void foo(float),dammit!>
但无法让任何人编译.
此外,显然可以在d中定义所需的重载来调用b的重载
- struct d : private b {
- void foo(float f) { b::foo(f); }
- };
但问题是如果有可能只是简单地使用.