LiDongning
2009-09-10 19:59:17 UTC
Hi,
I want to declare a function template as a friend in a nested class
template. The code is as follows.
template <class T>
class a1
{
public:
class a2
{
T att;
template <class T> friend const typename a1<T>::a2 operator +
(const typename a1<T>::a2&, const typename a1<T>::a2&);
};
};
template <class T>
const typename a1<T>::a2 operator + (const typename a1<T>::a2&, const
typename a1<T>::a2&)
{
return a1<T>::a2 xx;
}
int main()
{
a1<int> x;
a1<int>::a2 y;
y + y; //error! c2783
system("PAUSE");
return 0;
}
Complied in VC2008. Got error C2783. Tried couple of hours, just could
not make it work. Could somebody please help? Thanks very much!
I want to declare a function template as a friend in a nested class
template. The code is as follows.
template <class T>
class a1
{
public:
class a2
{
T att;
template <class T> friend const typename a1<T>::a2 operator +
(const typename a1<T>::a2&, const typename a1<T>::a2&);
};
};
template <class T>
const typename a1<T>::a2 operator + (const typename a1<T>::a2&, const
typename a1<T>::a2&)
{
return a1<T>::a2 xx;
}
int main()
{
a1<int> x;
a1<int>::a2 y;
y + y; //error! c2783
system("PAUSE");
return 0;
}
Complied in VC2008. Got error C2783. Tried couple of hours, just could
not make it work. Could somebody please help? Thanks very much!