Problem with pointers on template class in another class

Joined
Mar 7, 2010
Messages
1
Reaction score
0
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top