June 27, 2003 friend of a class template | ||||
---|---|---|---|---|
| ||||
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?
|
August 22, 2003 Re: friend of a class template | ||||
---|---|---|---|---|
| ||||
Posted in reply to Christof Meerwald | 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
|
Copyright © 1999-2021 by the D Language Foundation