如何在派生类中访问基类中的所有隐藏名称?

j4x*_*j4x 5 c++ using-declaration name-lookup name-hiding

从这个问题开始:

并考虑这个简化的代码:

#include <string>
#include <iostream>

class Abstract
{
public:
    virtual void method(int a)
    {
        std::cout << __PRETTY_FUNCTION__ << "a: " << a << std::endl;
    }
};

class Concrete : public Abstract
{
public:
    void method(char c, std::string s)
    {
        std::cout << __PRETTY_FUNCTION__ << "c: " << c << "; s: " << s << std::endl;
    }
};

int main()
{
    Concrete c;
    c.method(42);    // error: no matching function for call to 'Concrete::method(int)'
    c.method('a', std::string("S1_1"));

    Abstract *ptr = &c;
    ptr->method(13);
    //ptr->method('b', std::string("string2"));    <- FAIL, this is not declared in Abstract.
}
Run Code Online (Sandbox Code Playgroud)

我有两个疑问。1.我知道我可以解决这个错误,如果我“进口”一个method从名称Abstract

using Abstract::method;
Run Code Online (Sandbox Code Playgroud)

但随后我导入了该名称的所有重载。 是否可以只导入给定的重载? (假设Abstract有多个重载,例如:)

virtual void method(int a) = 0;
virtual void method(std::string s) = 0;
Run Code Online (Sandbox Code Playgroud)
  1. 是否可以一次导入所有(公共|受保护|所有)名称Abstract而不一一列出它们?

(现在假设除了methodAbstract还有:)

virtual void foo() = 0;
Run Code Online (Sandbox Code Playgroud)