Tony Johansson wrote:
Hello experts!
I know it's easy to override when you have inheritance.
But if you instead use object composition having a pointer to a class X.
If you want to override when having this object composition how is that
done.
Give some easy example if you have some.
I think you are going to have to provide an example to explain what you
mean. My problem is that I don't see what there is to override when you
have object composition, so I don't see how you can override composited
objects.
Suppose you have this
class X
{
void f();
void g();
};
class Y
{
void f() ( x_ptr->f(); }
void g() { /* do something else */ }
X* x_ptr;
};
Are you saying you want to pick and choose whether methods in Y call
methods in X? If that is what you want then you just write the code,
like I did above.
john