• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

[C++] Inheritance

Fare

Advanced OT User
Joined
Apr 3, 2008
Messages
2,387
Reaction score
151
Location
Ukraine
I'm stuck with some issue, and google isnt helping.
Lets say we got parent "class BaseSpell". Aswell as we got child class "class CombatSpell : public Event, public BaseSpell".

Later we declare an object of base class:
BaseSpell* spell;

I always thought that parent class cannot contain child class(or its gonna take only those elements which are same in parent&&child). But later I saw such action:
CombatSpell* combatSpell = new CombatSpell(NULL, needTarget, needDirection);
spell = combatSpell;


And seems its actually working like I never expected, BaseSpell* spell contains fully working CombatSpell object. Can someone explain me, if thats true? Means object of parent class(BaseSpell in my case), can contain any child class(CombatSpell in my case)?
 
Last edited:
My only actual programming experience is in C#, and I'd call myself a novice at it, at best. However, I did some searching, and found this stackoverflow link on the issue that might help you understand it.

As the article states, though, it is against the OOP principles, and should(as far as I know), be avoided in favor of a cleaner solution.

Edit:

At second glance, I think I misunderstood your question :p

Try this link instead.
 
Last edited:
Back
Top