1

I want to inherit the constructor of the base class, but don't compile. How can I solve this problem without changing the class name?

class MyClass
{
public:
    class A
    {

    };
};

class MyClass2 : MyClass
{
public:
    class A : MyClass::A
    {
        //error: expected nested-name-specifier before ‘namespace’
        using (MyClass::A)::(MyClass::A);
    };
};

2 Answers2

2
using MyClass::A::A;

The constructor is referred to by a qualified name to the base class from which it should be imported, i.e. MyClass::A, and then again the class name to refer to the constructor, but only the class name, not a qualified name, i.e. A.

walnut
  • 21,629
  • 4
  • 23
  • 59
1

Does using MyClass::A::A; do what you want?

If you want to use method() from class MyClass::A, you have to write using MyClass::A::method;. In your case, method() is the constructor, named A().

Bktero
  • 722
  • 5
  • 15