Re: Templated friend classes

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ralf Goertz

    Re: Templated friend classes

    Victor Bazarov wrote:
    I would hope that the syntax
    >
    template<class Tclass Derived1: public Base<T>
    {
    ...
    template<friend class Derived2<T>;
    };
    >
    or
    >
    template<class Tclass Derived1: public Base<T>
    {
    ...
    template friend class Derived2<T>;
    };
    >
    would work, but IIRC they don't.
    Yes, you're right, they don't. At least not with my compiler. Is there a
    reason for this? I also tried to use a forward declaration of Derived2
    before the definition of Derived1 but obviously, those declaration
    aren't allowed for templated classes, either. Again, I don't see why. If
    a non-templated class is used in a forward definition, the compiler also
    doesn't know what types are in that class.

    Ralf
  • Ralf Goertz

    #2
    Re: Templated friend classes

    Ralf Goertz wrote:

    I also tried to use a forward declaration of Derived2 before the
    definition of Derived1 but obviously, those declaration aren't allowed
    for templated classes, either.
    That's nonsense. I didn't do it right (I added the ": public Base<T>"
    part to the forwarding declaration). Sorry for the noise.

    Ralf

    Comment

    Working...