I am trying to tackle a (probably fundamentally easy :) problem.
How do I fetch data from one function in class1 to another in class2?
I have my declarations.h file in which I declare my stuff:
class Player {
private:
int PosY;
int PosX;
public:
Player() {
PosY = 8;
PosX = 13;
};
int GetCoords(int i);
Player* player;
};
class DrawMap {
private:
public:
DrawMap() {
};
int showMap();
DrawMap* myMap;
};
In my functions.cpp file I include the declarations.h file, and define my class functions:
#include "declarations.h"
int Player::GetCoords(int i) {
if(i == 1) {
return PosX;
} else {
return PosY;
}
}
int DrawMap::showMap() {
int PosX = player->GetCoords(1); <-- This is wrong, but why and how?
return 0;
}
The compiler says
error: ‘player’ was not declared in this scopewhich I totally understand. DrawMap:: doesn't know what player is. But how do I get it to know that? Shouldn't Player* player be public and accessible?
TIA,
A


Sign In
Create Account

Back to top









