I have over 50 classes of information. I want each to have a name, description, and cost inside their respective class. Each time I go to create this array I end up with an error such as: Can't Initialize Data Member. I'm sure it has to do with how and where I am defining the array.
Can I initialize the array variable "description" outside the class and then define it inside each of them? Or does this require a base class and for the others to inherit?
I thought the code would be something similar to this, but anytime I attempt to set the variables equal to something it tells me I don't have access to them.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
class Character{
public:
int xp;
std::string script;
std::string name;
void fill(int, string, string);
};
void fill (int xp, string script, string name){
};
class Believer :Character{
};
Thank you, however I'm having trouble understanding how I set and call information from the class. For an example inside State.cpp in my switch(sug) I have: cout <<" " << believer1.xp << endl;"
The intention is for the experience cost to be output, however the compiler says its undefined. I assume this has something to do with my includes?
#ifndef state_H
#define state_H
#include <iostream>
#include "database.h"
usingnamespace std;
int sug = 99; //if 99 there is a problem
int background;
int merit;
void pkstate(char state);
void templ();
void lucid(char state);
void legacy();
#endif
All of the Character objects that you have declared in the fill() exist only in that function. They cannot be accessed anywhere else.
If you need to access these Character objects in your main() then they need to be declared there (or globally).
I suggest replacing your fill() with a constructor for the class.
int main()
{
Character believer1( 0, "", "Believer" ), daredevill( 50, "Testing", "Daredevil" );
// and so on.
// now call functions like pkstate(), but pass the Character object to it!
pkstate( 'A', daredevill );
return 0;
}