override when using object composition

T

Tony Johansson

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.

Many thanks!

//Tony
 
J

John Harrison

Tony said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top