locked
Problem with Inheritance RRS feed

  • Question

  • Hi,

     

    A very simple test (I thought):

    Code Snippet

    class Basis
    {   
    protected:
       Basis() {}
    };

    class Test : public Basis
    {
    public:
       Test(int iNum) : Basis() {Basis obj = Basis();}
    };

    That work but

    Code Snippet

    class Basis
    {   
    protected:
       Basis(int I) {}
    };

    class Test : public Basis
    {
    public:
       Test(int iNum) : Basis(iNum) {Basis obj = Basis(5);}
    };

     

     

    dont work:

    1>.\test.cpp(18) : error C2248: 'Basis::Basis' : cannot access protected member declared in class 'Basis'
    1> .\test.cpp(12) : see declaration of 'Basis::Basis'
    1> .\test.cpp(10) : see declaration of 'Basis'

    Someone know why the 2. example dont work?

    Monday, July 9, 2007 3:04 PM

Answers