friend declaration for template class

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • john smith

    friend declaration for template class

    Hi, I have a class like so...

    template<class XV, class T> class Foo {
    Bar<T>* b;
    };

    and another class
    template<class T> class Bar {
    public:
    friend template<class XV, class T> class Foo<XV,T>; // wrong
    friend class Foo;
    // wrong
    friend class Foo<XV,T> //
    wrong
    };

    so what is the correct way to give Foo access to Bar's members? Thanks..

    Smith


  • Victor Bazarov

    #2
    Re: friend declaration for template class

    "john smith" <asdf@asdf123as df.net> wrote...[color=blue]
    > Hi, I have a class like so...
    >
    > template<class XV, class T> class Foo {
    > Bar<T>* b;
    > };
    >
    > and another class
    > template<class T> class Bar {
    > public:
    > friend template<class XV, class T> class Foo<XV,T>; // wrong
    > friend class Foo;
    > // wrong
    > friend class Foo<XV,T>[/color]
    //[color=blue]
    > wrong
    > };
    >
    > so what is the correct way to give Foo access to Bar's members? Thanks..[/color]

    template<class XV, class U> friend class Foo;

    Victor


    Comment

    • Victor Bazarov

      #3
      Re: friend declaration for template class

      "john smith" <asdf@asdf123as df.net> wrote...[color=blue]
      > Hi, I have a class like so...
      >
      > template<class XV, class T> class Foo {
      > Bar<T>* b;
      > };
      >
      > and another class
      > template<class T> class Bar {
      > public:
      > friend template<class XV, class T> class Foo<XV,T>; // wrong
      > friend class Foo;
      > // wrong
      > friend class Foo<XV,T>[/color]
      //[color=blue]
      > wrong
      > };
      >
      > so what is the correct way to give Foo access to Bar's members? Thanks..[/color]

      template<class XV, class U> friend class Foo;

      Victor


      Comment

      Working...