Passing derived class object array in place of base class object array
justanotherguy63_at_yahoo.com
Date: 12/02/04
- Next message: Ricky Corsi: "Re: polymorphism and protected help"
- Previous message: Ashish: "Re: Data Recovery Book"
- Next in thread: broeni: "Re: Passing derived class object array in place of base class object array"
- Reply: broeni: "Re: Passing derived class object array in place of base class object array"
- Reply: Tom Widmer: "Re: Passing derived class object array in place of base class object array"
- Reply: Dietmar Kuehl: "Re: Passing derived class object array in place of base class object array"
- Reply: Andrew Koenig: "Re: Passing derived class object array in place of base class object array"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 2 Dec 2004 00:51:28 -0800
Hi,
I am designing an application where to preserve the hierachy and for
code substitability, I need to pass an array of derived class object in
place of an array of base class object. Since I am using vector
class(STL), the compiler does not allow me to do this.
I do realize there is a pitfall in this approach(size of arrays not
matching etc), but I wonder how to get around this problem. I have a
class hierachy with abstract base class and all I wonder why the
principle of passing a derived class reference in place of base class
is not extended to arrays. After all, we are making the code more
substitutable right? How do we achieve substitutability in this case?
To me at least, not having to make needless changes to code and having
the ability to sort things out dynamically using inheritance has always
sounded crisp.
Also, does this problem mean there is some deficiency in my application
design? Any light you throw on this will be greatly appreciated.
Thanks.
justanotherguy
- Next message: Ricky Corsi: "Re: polymorphism and protected help"
- Previous message: Ashish: "Re: Data Recovery Book"
- Next in thread: broeni: "Re: Passing derived class object array in place of base class object array"
- Reply: broeni: "Re: Passing derived class object array in place of base class object array"
- Reply: Tom Widmer: "Re: Passing derived class object array in place of base class object array"
- Reply: Dietmar Kuehl: "Re: Passing derived class object array in place of base class object array"
- Reply: Andrew Koenig: "Re: Passing derived class object array in place of base class object array"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|