|
-
January 16th, 2009, 09:36 AM
#13
Re: Multiple Inheritance and Casting
 Originally Posted by TheCPUWizard
Not at all. You implement the method on the class, and it redirects, you NEVER perform a cast.
What about when implementing the method on the class doesn't make sense (or is impossible). For example what if you are inheriting from a class where you don't have the source (i.e. from a code library or something). Or what about something like:
Code:
class Person
{
...
}
class Banker : Person
{
}
class BasketballPlayer : Person
{
int GetPointsPerGame();
}
Now suppose you have a "Person" object and you know it is a BasketballPlayer object (for various reasons). You need to call the GetPointsPerGame.
Obviously you shouldn't just put "GetPointPerGame" into the Person class since that doesn't make sense. The only way to get the info you need is to cast it to a BasketballPlayer.
I realize this example is a bit arbitrary, but it illustrates my question fairly well. It seems like you are suggesting that casting should always be avoided, yet there are cases where it seems to me it is necessary.
Eggman
Using: VS 2008 w. Net 3.5
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|