提问人:glades 提问时间:6/29/2023 更新时间:6/29/2023 访问量:29
将基类的某些重载导入派生 [duplicate] 的私有作用域
Import certain overloads of base class to private scope of derived [duplicate]
问:
使用 using 指令,我能够从基类中选择一组特定的方法以放入不同的访问范围。对于方法的单个重载,这是否也是可能的?像这样的东西:
#include <iostream>
class base {
public:
auto print() -> void {
std::cout << "Hello World" << std::endl;
}
auto something_else(int) -> void {
std::cout << "Hello int stuff" << std::endl;
}
auto something_else(bool) -> void {
std::cout << "Hello bool stuff" << std::endl;
}
};
class derived : public base {
public:
using base::something_else(bool);
private:
using base::something_else(int);
};
int main() {
derived d;
d.print();
d.something_else(2);
d.something_else(true);
}
答: 暂无答案
评论