T
Tapeesh
I have a following piece of code. The code was compiled using g++
class A
{
public :
virtual void fn() = 0;
};
class B: virtual private A
{
public:
void fn() { cout << "I m here\n"; }
};
class C : public virtual A
{
};
class D : private B, virtual public C
{
};
int main()
{
D *mod1 = new D;
A *mod2 = mod1;
mod2->fn();
/* The following commented code does not compile */
/*
D *dObj = new D;
dObj->fn();
*/
return 0;
}
In this code how is the function fn() accessible to mod2 given that
class D is privately inheriting the implemetation of fn() from B.
Should it not be that, since implementation of fn() is privately
inherited from B the compiler should give B::fn() not accessible error
?
When the commented code is compiled, the compiler gives the error. This
is expected.....
So, how in the first case the resolution of a function call being done ?
class A
{
public :
virtual void fn() = 0;
};
class B: virtual private A
{
public:
void fn() { cout << "I m here\n"; }
};
class C : public virtual A
{
};
class D : private B, virtual public C
{
};
int main()
{
D *mod1 = new D;
A *mod2 = mod1;
mod2->fn();
/* The following commented code does not compile */
/*
D *dObj = new D;
dObj->fn();
*/
return 0;
}
In this code how is the function fn() accessible to mod2 given that
class D is privately inheriting the implemetation of fn() from B.
Should it not be that, since implementation of fn() is privately
inherited from B the compiler should give B::fn() not accessible error
?
When the commented code is compiled, the compiler gives the error. This
is expected.....
So, how in the first case the resolution of a function call being done ?