First off, I'm not totally sure how to Title my question.
I have a question about inheritance.
Let's say I make a class called Class_A:
class Class_A
{
public:
int a;
int b;
};
Then, I make Class_B, which inherits Class_A:
class Class_B : public Class_A
{
public:
int c;
int d;
}
Then I make an instance of Class_B:
Class_B my_class_b;
Now, I have a function that takes an instance of a Class_A, changes it, and then returns a Class_A:
Class_A func (Class_A which)
{
which.a += 20;
which.b -= 20;
return which;
}
What I'm trying to accomplish is, I want to be able to pass any Class_A into the function, and then assign the changes back to whatever was passed into it.
I tried this:
Class_A temp = func (my_class_b);
my_class_b = temp;
Passing my_class_b in for a Class_A works, but assigning it back to my_class_b doesn't.
I get a:
no match for 'operator=' in 'my_class_b = temp'
What is the best way to go about doing this? Thanks for any help.