Hey yes this can be a bit tricky, mostly because there are different ways to set up the relationships amongst ofApp, Map, and Agent. Its common though for Map and Agent to be separate things, each with an instance in ofApp.
// in ofApp.h
Map map;
Agent agent;
Then, in the Agent class, you could have a public function that accepts a Map instance as an argument, which then calls a public function in Map.
// in ofApp.cpp
// send map to agent
agent.setValuesInMap(map, position.x, position.y);
// in class Agent
// map is maybe big, so pass by reference, not by copy
void Agent::setValuesInMap(Map& map, float x, float y){
// do something with x and y in instance map
map.doSomething(x, y);
}
// in class Map
void Map::doSomething(float x, float y){
}
The Map& argument type means that you’re sending the real, official instance map to the function in Agent where it can be modified. This is known as passing by reference. Its nice and fast to do this for large objects where making a copy would require resources. I like to think of a reference as a pointer that you don’t have to dereference to use.
If the classes are all in separate .h files, make sure to #include them as needed, so the complier can find them:
// in ofApp.h
#include "map.h";
#include "agent.h";
// in agent.h
// Agent needs to know what a Map is, so
#include "map.h";
Now, there are lots of other ways to do this. How its done depends a lot on how you want to define the relationships amongst the 3 classes. Some will be more safe or straight forward than others. If this is confusing just post back and I’ll write a quick example that compiles.