im getting this error invalid use of non static data member.
my code looks something like this:
i have a main.cpp and 2 class files with respective .h files
say one class file is named human (so i have human.cpp and human.h) and stats (so i have stats.cpp and stats.h)
in my stats.h file, i have a double array: double HumanF[10][12] with everything filled in.
then in my human.h file i just have a bunch of integers.
human.cpp has formulas in it that use numbers from the double array i mentioned.
for example
Human::Human()
{
constant (this is a double i made in human.h) = (1+Stats::HumanF[0][0]);
i (another double) = pow(constant, ylvl);
(ylvl is also an int I made in my header file)
yhp = i*137;
}
my problem starts at the first line.
is there something im missing? thanks.
what is also weird is that in this class where i have the array (stats.h), i cannot enum it, it gives me the same error even though im saying const int BLAH = 10 and const int BLAH2 = 12
Hmm seems i have figured it out. i wasnt using the right header (i have many). Can i not use 2 classes in one .cpp file? it gives me an error when i do that
@cire
it gives me an error saying out of line declaration of a member must be a definition.
im using 1 class which is in one header and another class which is in another header
Human::Human() <- its giving me the error here.
Stats::Stats()
and tells me to put a ; like this
Stats::;Stats()
it gives me an error saying out of line declaration of a member must be a definition.
And so it must. You cannot 'declare' a method outside of the class definition, but you can define it there. In other words, outside the class definition, Human::Human() must be followed by the body of the function surrounded by curly braces: {}.
cire wrote:
Rather than describe it, reduce it to a minimal code sample that reproduces the problem
What error are you getting? Could we see your stats.h file? The most likely thing I can think of is that there is no default constructor for your stats class.
im trying to make separate code that does almost the same thing in each cpp file and trying to build it with that when i should be using cpp's in another cpp which will go into main... if that makes sense. use of undeclared identifier when i type stats. im going to try the way i just mentioned and see if that fixes it, im thinking it should.