www.digitalmars.com         C & C++   DMDScript  

c++.beta - template friend class

template<class T> struct A;

template<class T>
struct B
{
  template<class Y> friend class A;

 private:
  int i;
};

template<class T> struct A
{
  A()
  { }

  template<class Y>
  A(B<Y> &b)
  {
    b.i = 0;
    // Error: member 'B<int >::i' of class 'B<int >' is not accessible
  }
};


int main()
{
  A<int> a;
  B<int> b;

  A<int> a2(b);

  return 0;
}


Extracted from Boost's smart_ptr library.


bye, Christof

-- 
http://cmeerw.org                                 JID: cmeerw jabber.at
mailto cmeerw at web.de

...and what have you contributed to the Net?
Jun 28 2003