c++ - Initiating a derived class with specific variable values -


For the code snippet given below, how do I start an example of class anime with variables (like X, Y, Type)? I am working it correctly, it triggers instances, even though how many of them join ... I have to know the best way to make an enemy with only a few variables which will be different for each of my examples. Especially when some are in the base class of those variables and others are not. Class BaseObject {Public: Virtual Zero Render () = 0; Int x; Int y; }; Square Enemies: Public Base Object {Public: Enemy () {} Virtual Zoom Render () {cout & lt; & Lt; "Submit Enemy" & lt; & Lt; Endl; Type Type std :: set & lt; BaseObject * & gt; GAMEOBJECTS; GAMEOBJECTS g_gameObjects; Int main () {g_gameObjects.insert (new enemy ()); G_lootObjects.insert (new booty); (For GAMEOBJECTS :: iterator = g_gameObjects.begin (); it! = G_gameObjects.end (); This ++) {(* it - -) Render (); } (GAMEOBJECTS :: Iterator = g_lootObjects.begin (); it! = G_lootObjects.end (); this ++) {(* it) -> Render (); } Return 0; }

Include logic in enemy manufacturer and base constructors. You can use the member to initialize the variable. BaseObject {public: BaseObject (int x, int y): x (x), y (y) {} submission of virtual zeros () = 0; Int x; Int y; }; Class enemy: public base object {public: enemy (int x, int y, int foo): base object (x, y) and , Foo (Foo) {} int foo; ...};

Comments