Quantcast
Channel: Questions in topic: "class instance"
Viewing all articles
Browse latest Browse all 131

I made a child class of another child class, and if I declare new variables/functions in the first child class I am forced to also declare them in the parent

$
0
0
Basically, I have made: - a parent class for behaviors "CreatureBehavior" - a child class for a builder npc "BuilderBehavior", which inherits from "CreatureBehavior" - a function inside "BuilderBehavior" for building roads BuildRoad(). - a child class for a builder npc of a specific race "CirclerBuilderBehavior", which inherits from "BuilderBehavior" (He'll build different things than other builder races) - an override in the class "CirclerBuilderBehavior" for the BuildRoad() function The problem is that if I declare a variable "behavior" of type "CreatureBehavior", the main parent class, even if i use "behavior = new CirclerBuilderBehavior()" I cannot access the function BuildRoad() that I declared in the first child class since "it's not declared in the parent class CreatureBehavior". The goal is not to declare the function BuildRoad() in the parent class "CreatureBehavior", because if I happen to make a behavior child class for bears, for exemple, I don't plan on making the bears build roads... ![alt text][1] ![alt text][2] [1]: /storage/temp/204216-capture6.png [2]: /storage/temp/204217-capture7.png

Viewing all articles
Browse latest Browse all 131

Trending Articles