neverending Error!

closed account (LAfSLyTq)
Error code:
1>------ Build started: Project: Game1, Configuration: Debug Win32 ------
1> Main.cpp
1>c:\users\jeremy\documents\visual studio 2010\projects\game1\game1\main.cpp(145): error C2597: illegal reference to non-static member 'Player1::level'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

my Code:
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#include <iostream>
#include <string>
#include <ctime>
#include <cstdlib>
using namespace std;

	int damageDealt;
	char name[10];
	char Action;
	 
void namephase()
	{
		cout<<"\n\nEnter Your name."<<endl;
	cin>>name;
	cout<<"Your name is "<<name<<"?\n 1=Yes 2=No"<<endl;
	cin>>Action;
	if(Action=='1')
	{
		cout<<"Very well\n"<<endl;
	}
	if(Action=='2')
	{
		cout<<"What is your name?"<<endl;
		cin>>name;
		cout<<"Your name is now "<<name<<"!\n"<<endl;
	}
	else
	{
		cout<<"Please enter a valid name!"<<endl;
		namephase();
	}
	}

class Boar1;
class Player1;
void battlePhase(Player1 &player, Boar1 &boar);

class Player1
{
public:
    int health;
    int exp;
    int level;
    int atk;
    Player1 ()
    {
        health = 20;
        level = 1;
        exp = 0;
        atk = 5;
        damageDealt = atk;
    }
};


class Boar1
{
public:
    int health;
    int level;
    int atk;
    Boar1 ()
    {
        health = 20;
        level = 1;
        atk = 5;
    }
};

void battlePhase(Player1 &player, Boar1 &boar)
{
    cout <<"You have run into a Boar!\nWhat do you want to do?\n1=Attack "<<endl;
    cin >> Action;

    if ( Action == '1' || Action == 'i' )
    {
        cout<<name<<" attacked enemy for " <<player.atk<< endl;
        boar.health = boar.health - damageDealt;

        if ( damageDealt < 0 )
        {
            damageDealt = 0;
            cout<<"No damage!"<<endl;
        }
        else if ( damageDealt == 0 )
            cout <<"No damage!"<<endl;
        else if ( damageDealt > 0 )
            cout << "enemy" << " took " << damageDealt << " damage!";

        if(boar.health == 0)
        {
            cout<<"enemy has died!"<<endl;
            cout<<"you have gained "<<"50"<<" exp!"<<endl;
            system ("CLS");
            player.exp += 50;
        }
        else
        {
            cout << "\nThat isn't an action! Try typing '1'.";
            battlePhase(player,boar);
        };

        if(player.exp>=0 && player.exp<99)        player.level=1;
        if(player.exp>=100 && player.exp<199)    player.level=2;
        if(player.exp >=200 && player.exp <299)    player.level=3;
        if(player.exp>=300 && player.exp<399)    player.level=4;
        if(player.exp>=400 && player.exp<499)    player.level=5;
        if(player.exp>=500 && player.exp<999)    player.level=6;
        if(player.exp>=1000 && player.exp<1999)    player.level=7;
        
        cout<<"Congratulations, you are now level "<<player.level<<"!"<<endl;
        system ("pause");
    }
}
int main()
{
Player1 player;
Boar1 boar;

namephase();
cout<<Player1::level<<endl; //Error is Player1::level
battlePhase(player, boar);
return 0;
}


what happens is this
"1>c:\users\jeremy\documents\visual studio 2010\projects\game1\game1\main.cpp(145): error C2597: illegal reference to non-static member 'Player1::level'"

and if i change the int level and stuff to a static int, i get 2x more errors up at the top.
closed account (LAfSLyTq)
help.
cout<<Player1::level<<endl;

->

cout << player.level << endl;

And stop bumping so damn much, 1 time per 24 hrs please or people will eventually stop answering your questions
Topic archived. No new replies allowed.