www.digitalmars.com         C & C++   DMDScript  

c++.beta - friend of a class template

reply Christof Meerwald <cmeerw web.de> writes:
template<class T>
struct A;

template<class T>
void f();

template<class T>
struct A
{
  friend void f<T>();
  // Error: 'f' is not a class template
};


int main()
{
  A<int> a;

  return 0;
}


See 14.5.3 Friends [temp.friend], paragraph 1.

Extracted from Boost's format library.


bye, Christof

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

...and what have you contributed to the Net?
Jun 27 2003
parent Christof Meerwald <cmeerw web.de> writes:
and a similar one with an operator:

template<class T>
struct A;

template<class T> void f(const A<T> &a, int i)
{
  if (a.i == i);
}

template<class T> void operator << (const A<T> &a, int i)
{
  if (a.i == i);
}

template<class T>
struct A
{
  friend void f<T>(const A<T> &, int i);
  // Error: 'f' is not a class template

  friend void operator << <T>(const A<T> &, int i);
  // Error: only classes and functions can be friends

 private:
  int i;
};


int main()
{
  A<char> a;

  f(a, 0);
  a << 0;

  return 0;
}


bye, Christof

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