Self-referencing templates

From: Christopher Benson-Manica (ataru_at_nospam.cyberspace.org)
Date: 03/23/04


Date: Tue, 23 Mar 2004 15:47:45 +0000 (UTC)

Ugh, I'm having a time wrapping my mind around how this should work.
I have a template class that has a list of objects of another class.
That other class needs a reference to the object that owns it, an
instance of the first class. What's the correct way to declare that?

template class TClientHandler; // supposed to be a forward declaration
                               // - what's the syntax?

template <class T<T>> // Something?
class TTCPServer
{
  friend T; // Does it have to be T<T>? Or what...?
  std::vector<T>; // T<T>?
};

template <class T>
class TClientHandler
{
  TTCPServer<T<T>> *Owner; // :(
};

Can I not do this? If not, what's the alternative?

-- 
Christopher Benson-Manica  | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org    | don't, I need to know.  Flames welcome.


Relevant Pages

  • Re: Message Mapping for a template class
    ... > Does anyone know how to map messages for a template class? ... For even more fun ... ... declare some of the classes involved in a namespace! ...
    (microsoft.public.vc.mfc)
  • template typedef
    ... suppose I have a template class like: ... template <typename T> ... If I need a shared_ptr to this class I declare it like: ...
    (microsoft.public.vc.language)
  • Re: Template of interface?
    ... bonj wrote: ... > How do I declare a template class such that the template class T must ... > interface IProvideID ...
    (microsoft.public.vc.language)
  • Re: Template of interface?
    ... bonj wrote: ... > How do I declare a template class such that the template class T must ... > interface IProvideID ...
    (comp.lang.cpp)

Loading