1
#include <iostream> 
#include <chrono>    

class A{
    public:
        A(){} // default constr

};

class B:public A{
    public:
    using A::A;
    protected:

};

class C:public B{
    public:
        using A::A; //scope resolution 

        int f1(A a);// dummy function

};

int main () 
{ 
    return 0; 
} 

// Above program is working fine with C++ and C++14 but its giving error with C++17 // why and how can it be resolved?

songyuanyao
  • 169,198
  • 16
  • 310
  • 405
susheel chaudhary
  • 273
  • 3
  • 5
  • 8

1 Answers1

2

Yes, constructors could be inherited from only direct base class. [namespace.udecl]/3

If a using-declarator names a constructor, its nested-name-specifier shall name a direct base class of the class being defined.

You can inherit constructors from B in class C; the constructors of A have been inherited in B, then they'll be inherited in C too.

class C : public B {
    public:
        using B::B;
        //    ^^^^
};
songyuanyao
  • 169,198
  • 16
  • 310
  • 405