I have a class called MapGraph
and another class called GameState
. I'm calling two functions called GoToLocation(NextLocation);
and Game->SidePanel();
from main
. GoToLocation() declaration and definition exist in MapGraph.h
and MapGraph.cpp
respectively and SidePanel() declaration and definition exist in GameState.h
and GameState.cpp
respectively.
In SidePanel() I'm trying to get the value of a variable called CurrentLocation that exists in MapGraph
and is public. I've included MapGraph.h
in GameState.cpp
and declared the class as class MapGraph;
but I don't know how to get the value of the variable.
If I do MapGraph* Map = new MapGraph;
that always gives me the initial value of the variable and not the updated one.
Any help would be appreciated. Thank you.
The code in main.cpp:
int main()
{
MapGraph* Map = new MapGraph;
GameState* Game = new GameState;
//Game->MainMenu();
Map->GoToLocation(MapGraph::LocationNames::CastleSquare);
Game->SidePanel();
//system("CLS");
return 0;
}
MapGraph.h:
#pragma once
#include <iostream>
#include <list>
#include <string.h>
class MapGraph
{
public:
MapGraph();
enum class LocationNames
{
GraveYard = 0,
Sewers = 1,
Outskirts = 2,
Barracks = 3,
Town = 4,
CastleSquare = 5,
ThroneRoom = 6,
Forest = 7,
Gutter = 8,
HunterShack = 9
};
std::string LocNamesString[10] =
{
"Grave Yard",
"Sewers",
"Outskirts",
"Barracks",
"Town",
"Castle Square",
"Throne Room",
"Forest",
"Gutter",
"Hunter Shack"
};
LocationNames CurrentLocation;
void GoToLocation(LocationNames NextLocation);
};
and GameState.cpp:
#include <iostream>
#include <stdlib.h>
#include "GameState.h"
#include "MapGraph.h"
class MapGraph;
void GameState::SidePanel()
{
MapGraph* Map = new MapGraph;
std::cout << Map->LocNamesString[(int)Map->CurrentLocation];
}
P.S.: I tried changing CurrentLocation in MapGraph.h to static
but that always generates a linker error 2001. The error goes aways as soon as i remove the word static
.
Thank you.