问题
Starting from this question:
- Pointer derived from pure virtual class(A) can't access overload method from the pure class (B)
And considering this simplified code:
#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.
}
- (Try it)
I got two doubts.
1. I know I can solve the error if I "import" a method
name from Abstract
with
using Abstract::method;
but then I import all overloads of that name.
Would it be possible to import only a given overload?
(Suppose Abstract
has more than one overload like:)
virtual void method(int a) = 0;
virtual void method(std::string s) = 0;
- Is it possible to import all (public|protected|all) names from
Abstract
at once without listing them one-by-one?
(Now suppose that in addition to method
, Abstract
also has:)
virtual void foo() = 0;
来源:https://stackoverflow.com/questions/59758453/how-to-make-all-hidden-names-from-a-base-class-accessible-in-derived-one