Hi everyone. I've been learning C as my hobby for about 2 years now, and I've just recently decided that I've consumed enough knowledge to start working with C++. Anyhow the question at hand is regarding constructors and inheritance.
Assume that I had:
Now the problem that I'm having understanding is, when an Elemental object is created it also calls the Player class's constructor. For instance, maybe I don't want Player's constructor called every single time I create an Elemental object. Is there any way to get around this? I'm sure that there has to be a better way than how I'm doing this, because I'm a fledgling c++ programmer, lol.Code:class Player . . . class Elemental : public Player . . .
Here's a little snippet of code so that you can see what I'm talking about.
The output I get from the constructors on the console looks like this:Code:const int MAXP = 4; // Max count in Player array. const int MAXE = 15; // Max count in Elem array. Player pParty[MAXP] = { // Create array of characters. With different values. // Name Status Shield Health Mana Player("Paul", IsAlive, 2000, 150, -1), Player("Joe"), Player("Bob"), Player("Jason"), }; Elem pElem[MAXE] = { Elem("Fire"), Elem("Blaze"), Elem("Flare"), Elem("Burn",BURNING), Elem("Ice"), Elem("Blizzard"), Elem("FlashFreeze"), Elem("Freeze",FROZEN), Elem("Wind"), Elem("MicroBurst"), Elem("Tornado"), Elem("Confuse",CONFUSED), Elem("Water"), Elem("Geyser"), Elem("Flood") };
"Default" is a default name given to the object if a string wasn't specified as an argument when the object got created.Code:Constructing Player object Paul Negative found (-1) -- correcting. Constructing Player object Joe Constructing Player object Bob Constructing Player object Jason Constructing Player object Default Constructing Elem object Fire Constructing Player object Default Constructing Elem object Blaze Constructing Player object Default Constructing Elem object Flare Constructing Player object Default Constructing Elem object Burn Constructing Player object Default Constructing Elem object Ice Constructing Player object Default Constructing Elem object Blizzard Constructing Player object Default Constructing Elem object FlashFreeze Constructing Player object Default Constructing Elem object Freeze Constructing Player object Default Constructing Elem object Wind Constructing Player object Default Constructing Elem object MicroBurst Constructing Player object Default Constructing Elem object Tornado Constructing Player object Default Constructing Elem object Confuse Constructing Player object Default Constructing Elem object Water Constructing Player object Default Constructing Elem object Geyser Constructing Player object Default Constructing Elem object Flood Constructing Player object Default
Any ideas on how to get around this?



LinkBack URL
About LinkBacks
. Anyhow the question at hand is regarding constructors and inheritance.



... I'll have to keep that in mind while I'm learning this stuff.