V
vj
Hello Group,
I am C++/OOP newbie and was working on a project when i came accross
this puzzleing problem with inheritence.
C++ Code
==================
class Parent
{
protected:
int a;
};
class Childublic Parent
{
public:
int getA(Parent & p)
{return p.a;} //!!Compile time error:: Parent::a in-accessible
};
Java Code
=====================
class Parent
{
protected:
int a;
}
class Child extends Parent
{
public:
int getA(Parent p)
{return p.a;} //!! No Error
}
//************************************
Can anybody please tell me why c++ is not behaving the Java way. After
all 'Child' class was derived from 'Parent' class and thus should have
access to all the proctected members in objects of class 'Parent'.
Java is doing this fine but C++ is NOT!!
Thanks,
VJ
I am C++/OOP newbie and was working on a project when i came accross
this puzzleing problem with inheritence.
C++ Code
==================
class Parent
{
protected:
int a;
};
class Childublic Parent
{
public:
int getA(Parent & p)
{return p.a;} //!!Compile time error:: Parent::a in-accessible
};
Java Code
=====================
class Parent
{
protected:
int a;
}
class Child extends Parent
{
public:
int getA(Parent p)
{return p.a;} //!! No Error
}
//************************************
Can anybody please tell me why c++ is not behaving the Java way. After
all 'Child' class was derived from 'Parent' class and thus should have
access to all the proctected members in objects of class 'Parent'.
Java is doing this fine but C++ is NOT!!
Thanks,
VJ