I have a variable called "health" thats in a class called "player" and i need to use it in a class called "dinosaur" but i cant and i have never had to do this before and cant figure it out, can you please help.
// this dinosaur (acting as a trex) bites the player P
void dinosaur::trex(player& P)// by reference so it can be changed
{
int TrexHealth = 0;
int attacks[5] = {5,9,13,19,23};
time_t T;
time(&T);
srand(T);
int Time;
Time = rand() % 5;
TrexHealth = dinosaurHealth;
switch(Time)
{
case 0:
{
cout << "T-Rex used Bite!!" << endl;
P.health -= 5;// P's health decreased
}break;
}
}
C:\Users\Chay\Desktop\Dinosaur Arena\player.h||In constructor 'player::player()':|
C:\Users\Chay\Desktop\Dinosaur Arena\player.h|61|warning: statement has no effect|
C:\Users\Chay\Desktop\Dinosaur Arena\Dinosaur.h||In constructor 'dinosaur::dinosaur()':|
C:\Users\Chay\Desktop\Dinosaur Arena\Dinosaur.h|34|warning: statement has no effect|
C:\Users\Chay\Desktop\Dinosaur Arena\Dinosaur.h|65|error: prototype for 'void dinosaur::trex(player&)' does not match any in class 'dinosaur'|
C:\Users\Chay\Desktop\Dinosaur Arena\Dinosaur.h|18|error: candidate is: void dinosaur::trex()|
||=== Build finished: 2 errors, 2 warnings ===|
ok i changed it and am still getting errors, im not sure what they mean
C:\Users\Chay\Desktop\Dinosaur Arena\Dinosaur.h|18|error: 'player' has not been declared|
C:\Users\Chay\Desktop\Dinosaur Arena\Dinosaur.h||In constructor 'dinosaur::dinosaur()':|
C:\Users\Chay\Desktop\Dinosaur Arena\Dinosaur.h|34|warning: statement has no effect|
C:\Users\Chay\Desktop\Dinosaur Arena\Dinosaur.h|65|error: variable or field 'trex' declared void|
C:\Users\Chay\Desktop\Dinosaur Arena\Dinosaur.h|65|error: 'player' was not declared in this scope|
C:\Users\Chay\Desktop\Dinosaur Arena\Dinosaur.h|65|error: 'P' was not declared in this scope|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\winnt.h|2422|error: expected declaration before end of line|
||=== Build finished: 5 errors, 1 warnings ===|
C:\Users\Chay\Desktop\Dinosaur Arena\Dinosaur.h|18|error: 'player' has not been declared|
means you typed void trex(player&); instead of void trex(Player&); and the rest of the errors follow from this.
Oops. My bad. It should be player then.
I don't know what the problem is then. You have #include "player.h" at the top of dinosaur.h, so the compiler should recognize a player object.
The errors read like it doesn't know what a player is.
New code?
EDIT: You had no problem with line 74 player P; before right?
Weird.
Sorry, I don't see anything wrong.
Try void trex(player &P); for line 18 (ie. including the P).
I don't think that's necessary though, so it's a long shot.
Otherwise, I just don't see anything wrong.
I guess you will just have to ignore my advice and go back to what you had.
Sorry for trashing your thread.
there might be more going on here wrong than this but you definitely need to use your "set_health" and "get_health" functions of the player class inside the trex function.. ie...