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
    Likes Received:
    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.
     
    lorenzo17, Mar 7, 2010
    #1
    1. Advertisements

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. Phil
    Replies:
    1
    Views:
    782
    llewelly
    Sep 16, 2003
  2. christopher diggins
    Replies:
    16
    Views:
    1,042
    Pete Becker
    May 4, 2005
  3. jn@ngedit.com
    Replies:
    1
    Views:
    466
    Victor Bazarov
    Feb 17, 2006
  4. erictham115@gmail.com
    Replies:
    1
    Views:
    447
    John Harrison
    Feb 21, 2007
  5. Peng Yu
    Replies:
    3
    Views:
    984
    Thomas J. Gritzan
    Oct 26, 2008
  6. ymost@hotmail.com
    Replies:
    2
    Views:
    685
    ymost@hotmail.com
    Dec 28, 2008
  7. A L
    Replies:
    1
    Views:
    696
    Alf P. Steinbach /Usenet
    Aug 25, 2010
  8. cerr

    pointers, pointers, pointers...

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