Problem with pointers on template class in another class

Discussion in 'C Programming' started by lorenzo17, Mar 7, 2010.

  1. lorenzo17

    lorenzo17

    Joined:
    Mar 7, 2010
    Messages:
    1
    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.
    lorenzo17, Mar 7, 2010
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jn@ngedit.com
    Replies:
    1
    Views:
    345
    Victor Bazarov
    Feb 17, 2006
  2. erictham115@gmail.com
    Replies:
    1
    Views:
    315
    John Harrison
    Feb 21, 2007
  3. Peng Yu
    Replies:
    3
    Views:
    749
    Thomas J. Gritzan
    Oct 26, 2008
  4. A L
    Replies:
    1
    Views:
    493
    Alf P. Steinbach /Usenet
    Aug 25, 2010
  5. cerr

    pointers, pointers, pointers...

    cerr, Apr 7, 2011, in forum: C Programming
    Replies:
    12
    Views:
    642
Loading...

Share This Page