Hey everybody.
I am currently facing a problem with pointer of template class, and i cannot see any easy solution.
Here is the code :
// Agent.h
class Space;
template<class T> class Agent
{
public:
Agent(Space* a_space,...); // there are other variables here but not important for the code
virtual ~Agent();
.... (other member functions)
private:
Space* m_linkToSpace;
};
// Agent. cpp
#include "Space.h"
// declaration of Agent's functions
template class Agent<int>;
template class Agent<double>;
Then I have derived template agents from template class Agent.
Then all agents are in a space (or in a derived class from space)
// Space.h
template<class T> class Agent; // I tried also with #include "Agent.h"
class Space
{
public:
Space();
virtual ~Space();
... (other functions using pointers on Agent<T>)
private:
std::map<int,Agent<T>*> m_agents; // to store every agents in the space and their Ids.
};
// Space.cpp
#include "Agent.h"
// Declaration of Space's functions
This code does not compile because of Agent<T>* (it works when Space has no pointer on Agent<T>). I have tried different things (add some typename before Agent<T> or template<class T> friend class Agent or template Agent<int> at the end...) but none worked.
Does anyone see how to make the code works ?? THANK YOU !!
Lolo.
I am currently facing a problem with pointer of template class, and i cannot see any easy solution.
Here is the code :
// Agent.h
class Space;
template<class T> class Agent
{
public:
Agent(Space* a_space,...); // there are other variables here but not important for the code
virtual ~Agent();
.... (other member functions)
private:
Space* m_linkToSpace;
};
// Agent. cpp
#include "Space.h"
// declaration of Agent's functions
template class Agent<int>;
template class Agent<double>;
Then I have derived template agents from template class Agent.
Then all agents are in a space (or in a derived class from space)
// Space.h
template<class T> class Agent; // I tried also with #include "Agent.h"
class Space
{
public:
Space();
virtual ~Space();
... (other functions using pointers on Agent<T>)
private:
std::map<int,Agent<T>*> m_agents; // to store every agents in the space and their Ids.
};
// Space.cpp
#include "Agent.h"
// Declaration of Space's functions
This code does not compile because of Agent<T>* (it works when Space has no pointer on Agent<T>). I have tried different things (add some typename before Agent<T> or template<class T> friend class Agent or template Agent<int> at the end...) but none worked.
Does anyone see how to make the code works ?? THANK YOU !!
Lolo.