[c++] Przyjazn i szablony

0

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??

0
#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<< <TYP>(ostream&, Wektor<TYP>); //brakuje <TYP> po nazwe funkcji

                friend istream& operator>> <TYP>(istream&, Wektor<TYP>&); // to samo
};

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;
}
0

Wszystko śmiga. Dzięki [browar] ;)

0
#include <iostream>
using namespace std;

template<class TYP> class Wektor
{
        public:
                TYP x, y, z;
                //konstruktory, funkcje skladowe i caly ten stuff ;)
                friend ostream& operator<<(ostream& strumien, Wektor<TYP> w) {
                            strumien << w.x << " " << w.y << " " << w.z << endl;
                            return strumien;
                }

                friend istream& operator>>(istream& strumien, Wektor<TYP>& w) {
                            strumien >> w.x >> w.y >> w.z;
                            return strumien;
                }
};

Na podstawie: http://smart2help.com/e-books/ticpp-2nd-ed-vol-two/#_Toc53985727

1 użytkowników online, w tym zalogowanych: 0, gości: 1