Invalid use of non-static data member?

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
Rather than describe it, reduce it to a minimal code sample that reproduces the problem:

1
2
3
4
5
6
7
8
9
10
11
12
struct A
{
    char a = 'a' ;
};

struct B
{
    char b;

    B() { b = A::a + 1;}

};


An object of type A is required to access the a member of an A object. For instance, the following would work:

1
2
3
4
5
6
7
8
9
10
11
12
struct A
{
    char a = 'a';
};

struct B
{
    char b;

    B() { A x; b = x.a + 1;}

};


Or, if we make the member static there will only be one a for all objects of type A, and then the original code works:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
struct A
{
    static char a ;
};

char A::a = 'a';

struct B
{
    char b;

    B() { b = A::a + 1;}

};
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
Can i not use 2 classes in one .cpp file? it gives me an error when i do that

Of course you can.
@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()
xystus wrote:
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
oh i see.
Now ive run into another file.
i have 2 separate .h files with respective .cpp files
human.cpp
human.h
stats.cpp
stats.h

i include both in my main file.
#include "human.h"
#include "stats.h"

both have their own classes named human human() and stats stats() respectively.
when i go to my main and type
human();

in my main function and run it, it does everything its supposed to.

but, when i type
stats();

i get an error.

now what am i missing!?
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 actually thinking of redoing these.

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.
oh derp... i had something wrong with my header files. everything works fine now :3
Topic archived. No new replies allowed.