a question about slicing
From: glen_stark (stark_at_ifh.ee.ethz.ch)
Date: 03/31/04
- Next message: Alf P. Steinbach: "Re: display stack"
- Previous message: Steven T. Hatton: "Re: An Interesting Gotcha"
- Next in thread: bartek: "Re: a question about slicing"
- Reply: bartek: "Re: a question about slicing"
- Reply: John Harrison: "Re: a question about slicing"
- Reply: glen_stark: "Re: a question about slicing"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 31 Mar 2004 09:00:43 -0800
Hi everyone.
I want to make sure I understand something correctly. If I have a base
and inherited classes, say shape
/ \
box poly
Now let's say I have a list of pointers to shapes, and I need to create
copies of some of the shapes (which could be boxes or polys), I guess I
will have to provide a virtual copy function for box and poly, to ensure
I don't slice away any important information?
I guess what I'm asking is, if I use the default copy constructor, it
will create a copy of a shape, not of a box or a poly. Is this correct?
I'm also thinking, to prevent accidental slicing I can make shape
abstract?
Then my last question is, is there a preferred idiom for doing this?
should I just provide a member
class Shape{
virtual Shape* copy()=0;
}
for this kind of circumstance, or is there a more elegant solution?
Thanks for your time,
Glen Stark
- Next message: Alf P. Steinbach: "Re: display stack"
- Previous message: Steven T. Hatton: "Re: An Interesting Gotcha"
- Next in thread: bartek: "Re: a question about slicing"
- Reply: bartek: "Re: a question about slicing"
- Reply: John Harrison: "Re: a question about slicing"
- Reply: glen_stark: "Re: a question about slicing"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]