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);
    };
};
1
  • @uneven_mark thanks problem solved =) Commented Nov 8, 2019 at 14:59

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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().

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.