Dynamic Object Not Creating for Privately Inherited Class.

Posted by mahesh on Stack Overflow See other posts from Stack Overflow or by mahesh
Published on 2010-04-06T07:48:26Z Indexed on 2010/04/06 7:53 UTC
Read the original article Hit count: 203

Filed under:
|

Hi,

What is the reason for the following code that does not let me to create object.

class base
{
    public:
        void foo()
        { cout << "base::foo()"; }
};

class derived : private base
{
    public:
        void foo()
        { cout << "deived::foo()"; }
};

void main()
{
    base *d = new derived();
    d->foo();
}

It Gives me error :

" 'type cast' : conversion from 'derived *' to 'base *' exists, but is inaccessible"

Thanks in advance :)

© Stack Overflow or respective owner

Related posts about c++

Related posts about inheritance