Topic: inline template friend functions
Author: robh@uk.sun.com (Rob Hulme - Sun UK - PSG Engineer)
Date: 1995/07/24 Raw View
Hi All
consider the following snippet of code:
template <class T> class A
{
private:
T i;
public:
A(const T &);
A<T> & add(const A<T> &);
inline friend A<T> plus(const A<T> &a1, const A<T> &a2);
// ^^^^^^ note this
};
template <class T> inline A<T> plus(const A<T> &a1, const A<T> &a2)
{
return A<T>(a1.i + a2.i);
}
Now this is fine as it stands and compiles and links ok. However, if
I remove the inline from the class construct, plus() can not be resolved
at link time. Now I understand why this particular compiler needs to know
if this friend function is inline within the class construct, but I'm
wondering if this is just a requirement of the compiler or a requirement of
the language?
Thanks
Rob