I'm trying to have a member function of classA set valuea to what ever valueb of classB is. I don't really have a full grasp of inheritance so forgive me if it's a simple or stupid mistake. Also Would it be easier to make the convert function a friend of both classes instead?
class B
{
protected:
int valueb;
public:
B() { }
B(int x) {valueb=x;}
};
class A: public B
{
int valuea;
public:
A():B() {}
A(int x):B(x) {valuea=x;}
void convert(B x)
{
valuea = x.valueb;
}
int getValue() {return valuea;}
};
int main( )
{
A a(1);
B b(2);
a.convert(b);
cout << a.getValue() << endl;
}