0

I tried the following and failed to compile.

class A {
   
   //...members

   class B : public A {    //<---failed here
      using A::A;
      
   }
   
}

Is this possible(specially in c++17)? Do this just have wrong syntax? If not possible, why this does not work?

acegs
  • 2,621
  • 1
  • 22
  • 31

1 Answers1

3

This can be done, but the definition of B needs to be moved outside of A. Until the closing brace, A is an incomplete type, whereas the base class must be complete.

This would work:

class A {
   class B;
};

class A::B : public A {
    using A::A;
};
Igor Tandetnik
  • 50,461
  • 4
  • 56
  • 85
  • wow! good thing i ask here. i don't know that inner class can be defined later even before c++11. :) – acegs Aug 28 '20 at 03:58