Próbuję zaprzyjaźnić szablon funkcji z szablonem klasy, ale kompilator wywala mi błąd:
[C++ Error] Unit2.cpp(21): E2410 Missing template parameters for friend template 'ostream &(ostream &,Wektor<TYP>)'
[C++ Error] Unit2.cpp(22): E2410 Missing template parameters for friend template 'istream &(istream &,Wektor<TYP> &)'
Oto kod (skrócony):
#include <iostream>
using namespace std;
//Deklaracje:
template<class TYP> class Wektor;
template<class TYP> ostream& operator<<(ostream&, Wektor<TYP>);
template<class TYP> istream& operator>>(istream&, Wektor<TYP>&);
template<class TYP> class Wektor
{
public:
TYP x, y, z;
//konstruktory, funkcje skladowe i caly ten stuff ;)
friend ostream& operator<<(ostream&, Wektor<TYP>);//To tu jest problem (przynjamniej wg kompilatora)
friend istream& operator>>(istream&, Wektor<TYP>&);
};
template<class TYP> ostream& operator<<(ostream& strumien, Wektor<TYP> w)
{
strumien << w.x << " " << w.y << " " << w.z << endl;
return strumien;
}
template<class TYP> istream& operator>>(istream& strumien, Wektor<TYP>& w)
{
strumien >> w.x >> w.y >> w.z;
return strumien;
}
Co jest nie tak??