Game Classes

I get errors when running this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <iostream>
#define _WIN32_WINNT 0x0500
#include <windows.h>
#include <sstream>
#include <string>
#include "Color.h"

using namespace std;

class Dwarf
{
    public:
    Dwarf (string n, int a, int x, int y);
    ~Dwarf ();

    int age, Xpos, Ypos, carry;
    string job, name;
};

Dwarf::Dwarf (string n, int a, int x, int y) : name(n), age(a), Xpos(x), Ypos(y)
{}

Dwarf::~Dwarf(){};

int main()
{
    Dwarf Stubby("Stubby", 10, 10, 10);
    cout << Dwarf::age;
    //ParseInput();
}


Errors:

C:\Dev-Cpp\Stringbreaker\main.cpp||In constructor 'Dwarf::Dwarf(std::string, int, int, int)':|
C:\Dev-Cpp\Stringbreaker\main.cpp|17|warning: 'Dwarf::name' will be initialized after [-Wreorder]|
C:\Dev-Cpp\Stringbreaker\main.cpp|16|warning: 'int Dwarf::age' [-Wreorder]|
C:\Dev-Cpp\Stringbreaker\main.cpp|20|warning: when initialized here [-Wreorder]|
C:\Dev-Cpp\Stringbreaker\main.cpp||In function 'int main()':|
C:\Dev-Cpp\Stringbreaker\main.cpp|16|error: invalid use of non-static data member 'Dwarf::age'|
C:\Dev-Cpp\Stringbreaker\main.cpp|38|error: from this location|
||=== Build finished: 2 errors, 4 warnings (0 minutes, 2 seconds) ===|

Last edited on
The first three messages are warnings because your compiler is too stupid to realize that initialization order doesn't actually matter you in that case - in some cases it does matter and the warning would alert you to a bug, but not in this case.

As for the last two messages, that is actually an error. I think you meant to write "Stubby.age" instead of "Dwarf::age"
Topic archived. No new replies allowed.