我不知道當試圖重載>>和< <模板和重載的IStream
template<class T, int N> class vector{
friend istream &operator>> <T,N>(istream &, vector &);
friend ostream &operator<< <T,N>(ostream &, const vector &);
};
template<class T, int N>
istream &operator>>(istream &input, vector<T,N>& v)
{
for (int i=0; i<N; i++)
input >> v.component[i];
return input;
}
g ++編譯器說
vector.h:22:17: error: template-id ‘operator>><double, 2>’ for
‘std::istream& operator>>(std::istream&, vector<double, 2>&)’
does not match any template declaration
friend istream &operator>> <T,N>(istream &, vector &);
^
vector.h:23:17: error: template-id ‘operator<< <double, 2>’ for
‘std::ostream& operator<<(std::ostream&, const vector<double, 2>&)’
does not match any template declaration
friend ostream &operator<< <T,N>(ostream &, const vector &);
^
是'vecotr'您自己的類,還是它是'std :: vector' ?? –
這是我自己的班級。謝謝。 – user2448054