48 minutes ago, TheSpire said:
That effectively wouldn't do anything, casting is just changing how you interpret the type of a thing, and you're basically casting it to a staff and then setting a weapon reference to it, meaning if you try to access it through weapon you'll get a reference to a weapon back. If you wanted to access the -staff- part of weapon then you would just set the private weapon to the incoming staff, then cast it to a staff later when you need to cast it.
If effect that private Weapon is only ever going to act like a weapon, even if its pointing to a subclass of weapon like a Sword. Keyword Is would be using type identification to figure out it is a sword, which you could do, but has some caveats and I'm not sure about performance. In a language like C++ you'd usually provide some kind of identifier to know how to cast something to a subclass, like an enum you set.
I'm not entirely sure how that would help with the problem presented in the thread so far either. You could technically reject certain weapon types in the set function for weapon like that, but, you'd then need to know the types ahead of time, and you would probably be better served making something like an Equip function that does it instead. In the context of this thread I would suspect you'd get more than a few people saying that Staff and Sword do not necessarily even need to be a subclass of a weapon.