   Beginniner seeking help with CLASS
  Hi! This is my first post on the site. I am VERY new to programming, been learning c++ for about a month now.  I have been hitting the books pretty hard in my free time though, and feel i have a decent grasp of the basic syntax.Anyway, my question is about my latest programming endevor.  My first few projects were mostly pracitce.  I made one of those "magic number" games as my first complete program, and have made a pretty simple roulette type gambling game.  All text based of course.The current project is a "magic: the gathering" style 2 player battle rpg, for those of you familiar with that game.  The help I need is with this:  I have all the groundwork laid out and have a very good idea of how to impliment the code... accept one part.  I have three character types in the game(Necromancer, Druid, and Mage)... for these i made a player class{}player1, and player2.  All the character types are exactly the same accept for thier spells.  I am trying to figure out the most efficiant way to input unique spelleffect() functions into the player class, according to what character type they choose.  My idea for this was to make the spelleffect() functions pointer funtions inside the class, and to then point them to thier unique spell functions through a switch statements after the character select screen.Like i said, i am still a real newb, and don''t even know if i''m going about this the right way... so any help or guidence on this would be awsome!p.s. sorry for the extremely long post on such a short matter... i promise they won''t all be this long 
  er... what is "spelleffect()" meant to do?Could you tell us more about the architecture you have chosen?There aren''t ''player character classes'' in MTG, so could you tell us what they consist in?   Victor Nicollet, INT13 game programmer ;  Sorry, if it wasn''t clear what my question was... let me try to verbalize it a little better...I have one class set up like this, that represents the player character:class player{public:  int hp;  int mana;  int maxmana;   string name; //player name  string chartype; //i.e. necromancer, druid, mage  void spelleffect1(); /*these are different spells available to  void spelleffect2();   each charactertype(necro,mage ect.) but   void spelleffect3();   different for each one. one may be}player1, player2;  a healing spell while one may be adamage spell*/my question is... rather than have ALL the possible spell types for every character type in 1 class...  would it be possible to define the ''spelleffect()'' functions after the player chooses a character...In other words, after the character select screen:1)Necromancer2)Druid3)Magechoose:use a switch statement to then define the variables and functions of the class.switch(charchoice){case 1:   player1.hp = 100;   player1.mana = 10;this is were i am stuck... is it possible to make the spelleffect1() function a pointer inside the class? and then have it point to the correct function in the switch statement?class player{public:  int hp;  void *spelleffect1();}player1, player2;....after the character select screen....switch(charchoice){case 1:  player1.hp = 100;  player1.spelleffect = &necrospell1();}i hope this is a little clearer...although i don''t think it is like i said...i don''t even know if i am going about this the right way... basically i''m just trying to think of a way to make my class with out having to put every possible spell function into it... rather, have the set number of spells each character has, and then define those after the player chooses his/her character....   ;  what about inheritance?i mean keep your spelleffect methods out of the player class and derive three classes from it (necromancer, druid, mage). give those classes the spelleffects they need and thanclass player{public:int hp;int mp;virtual void special() const;};class mage : public player{public:void special();};player* _player = NULL;switch(charchoice){case 1: _player = new Mage;_player.hp = 100;_player.mp = 10;static_cast(_player)->spelleffect();}well maybe that helps (i''m quite sure there are better solutions but atm i can''t squeeze one out of my brain ;p);  Like Zeon said, you can use inheritance for this...but I would do it a bit different than he would.Create a SpellEffects class with a SpellEffects() virtual function and derive from it three classes:SpellEffectsNecro, SpellEffectsDruid, and SpellEffectsMage.Now you only need a single player class (or you still can use inheritance for the player class if you want to).  You will pass the player object an instance of either of the above three classes, depending on what type of character it is.  Your player object now only needs to call the SpellEffects() function of the passed objects when it needs to display the effects.This way, you can also hold spell effects-related data as well as instructions (even if you don't now, you may need to later).In fact, you can rename the three classes to something else so that the names are not class specific, then you can pass any of them to any player object you want.  A druid with necro spell effects anyone? =DNow if all of this is confusing...you can always do it the way you proposed.  I think its a fine way to do it...albeit it may not be very object oriented...if that concerns you that is.  In fact if you want the most efficient way...yours may actually be it =). [edited by - hapaboy55 on February 18, 2004 6:08:56 PM]