The problem is that when you do something like
template<class T>
class AA {friend void print(const AA<T>&);};
and you create an instance AAas follows
AA<int> a;
friend’s ad will be created in such a way as
friend void print(const AA<int>&);
which is a function without a template! This means that the compiler will not match a friend's declaration with the function print.
print AA , . :
#include <iostream>
using namespace std;
template<class T>
class AA;
template<class T>
void print(const AA<T> & z);
template <class T>
class AA
{
friend void print<>(const AA<T> & z);
public:
AA() {a = 7;}
private:
T a;
};
template<class T>
void print(const AA<T> & z)
{
cout<<"Print: "<<z.a<<endl;
}
int main()
{
AA<int> a;
print(a);
}
, , <> . . ? , print,
void print(const AA<int>&);
. print ( , ), , friend. , .