dimanche 3 janvier 2016

Protected constructor on parent and inherited default one not protected

I have a question about default constructor on inherited class when the parent one is protected, in my mind the child class will have a default one protected too, but it's not the case.

Is there's a way to force the default constructor to be protected other than force it on child class ?

C++11 - gcc version 5.3.1 20151219 (Debian 5.3.1-4).

int main ( int argc, char ** argv ) 
{
    using namespace std;

    class A
    {
     public:
       static std::shared_ptr<A> CreateInstance ()
       { 
           A * pInstance { new A };

           return { pInstance, []( A * pInstance )
           {
           delete pInstance;
           }};
       };

     protected:
       A () = default;
       ~A () = default;
    };

    class B : public A
    {
    };

    B b; // It's work !

    return 0;
}

Thanks for your help,

WCdr

Aucun commentaire:

Enregistrer un commentaire