im trying to make a game and i was wondering if you can use shared functions on multiple objects from console.
like i have four classes :warrior,thief,mage,archer
each one has a separate class defining their stats and etc
im curious if you can dynimically use a function on either of those objects
like if i selected warrior in the beginning all the function commands will apply to the warrior object.
instead of having a ton of these lines below in the code
All these objects have things in common. What you can do is define a class from which these objects inherit from and share the same interface. Then you define a pointer to a character, and use the characters interface to set the variables that the more specialized class uses.
at the moment they all derived from a class called Character which they do share the stat variables which are initialized when the warrior or etc objects are created. the thing is i have other functions that manipulate the stats in characters(warrior and etc) objects but im trying to avoid making 4 sets of them each for example
You would pass a character pointer to the function which takes a character class pointer, and the method acts ON THE CHARACTER CLASS, and not on the specific player archetype.
The only thing that the specific player types do is act specifically on actions that are relative only to that archetype. For example, a Mage isn't going to use an axe, but the warrior will. But each will attack, and by overloading the attack function which is virtual in the character base class, each specific player type can behave specifically without much modification to the underlying code. Make sense?