Yes, in my ever-stubborn quest for C++ knowlege, I have begun messing with structures (in which I should have before classes).
I have a problem, though. I have declared variables in the structure, and I declared an instance of the structure outside the structure. It's saying the same thing for each instance outside, " expected constructor, destructor, or type conversion before '.' token," and for every variable in the instance, it says the variable is undeclared.
I'll use the RPG example again, since that's what seems to give me the most problems...
Try compiling it and you'll see what I mean. It's got me stumped... any tips?Code:#include <cstdlib> #include <iostream> using namespace std; //START RACE STUFF************************************************* //START RACE STUFF************************************************* //START STRUCTURE struct Stats { void power (int pow); void vitality (int vit); void magic (int mag); void maxhealth (int maxh); void health (int hea); void maxmana (int maxm); void mana (int man); int displaypower(); int displayvitality(); int displaymagic(); int displaymaxhealth(); int displayhealth(); int displaymaxmana(); int displaymana(); int strength; int defense; int intelligence; int maxhp; int hp; int maxmp; int mp; }; //END STRUCTURE //START FUNCTION DECLARATION OF STRUCT void Stats::power (int pow) { strength=pow; } void Stats::vitality (int vit) { defense=vit; } void Stats::magic (int mag) { intelligence=mag; } void Stats::maxhealth (int maxh) { maxhp=maxh; } void Stats::health (int hea) { hp=hea; } void Stats::maxmana (int maxm) { maxmp=maxm; } void Stats::mana (int man) { mp=man; } int Stats::displaypower() { return strength; } int Stats::displayvitality() { return defense; } int Stats::displaymagic() { return intelligence; } int Stats::displaymaxhealth() { return maxhp; } int Stats::displayhealth() { return hp; } int Stats::displaymaxmana() { return maxmp; } int Stats::displaymana() { return mp; } //END FUNCTION DECLARATION OF STRUCT //START RACE SELECTION //1-human 2-dwarf 3-elf //human Stats human; human.power(10); human.vitality(10); human.magic(10); human.maxhealth(100); human.health(100); human.maxmana(10); human.mana(10); //dwarf Stats dwarf; dwarf.power(15); dwarf.vitality(15); dwarf.magic(5); dwarf.maxhealth(150); dwarf.health(150); dwarf.maxmana(5); dwarf.mana(5); //elf Stats elf; elf.power(5); elf.vitality(10); elf.magic(15); elf.maxhealth(50); elf.health(50); elf.maxmana(15); elf.mana(15); //hero Stats hero; //class integers and functions int char_race =1; void race_stats() { switch(char_race) { case 1: hero.power(human.power(pow)); hero.vitality(human.vitality(vit)); hero.magic(human.magic(mag)); hero.maxhealth(human.maxhealth(maxh)); hero.health(human.health(hea)); hero.maxmana(human.maxmana(maxm)); hero.mana(human.mana(man)); break; case 2: hero.power(dwarf.power(pow)); hero.vitality(dwarf.vitality(vit)); hero.magic(dwarf.magic(mag)); hero.maxhealth(dwarf.maxhealth(maxh)); hero.health(dwarf.health(hea)); hero.maxmana(dwarf.maxmana(maxm)); hero.mana(dwarf.mana(man)); break; case 3: hero.power(elf.power(pow)); hero.vitality(elf.vitality(vit)); hero.magic(elf.magic(mag)); hero.maxhealth(elf.maxhealth(maxh)); hero.health(elf.health(hea)); hero.maxmana(elf.maxmana(maxm)); hero.mana(elf.mana(man)); break; } } //END RACE SELECTION //END RACE STUFF*************************************************** //END RACE STUFF*************************************************** int main(int argc, char *argv[]) { system("PAUSE"); return EXIT_SUCCESS; }