Есть небольшая программа, реализующая односвязный список, вот вкратце код:
| Код | #include <iostream> #include <conio.h>
using namespace std;
template <class T> // один элемент списка struct term { term(): data(NULL), next(NULL) {} term(T d, term<T>* n = NULL): data(d), next(n) {} void print() { cout<<data<<"\t"; } term<T>* next; T data; };
template <class T> class list //наш класс { public: list(): h(NULL) {} //по умолчанию list(list<T>& ls); //копирующий list(T a[], int n); void add (term<T>* t); void print(); list<T>& operator=(list<T>& ls); T operator[] (int i); friend ostream& operator<< (ostream& out, list<T> ls); //вывод private: void reverse(); void clear(); term<T>* h; }; // тут реализация всех конструкторов, деструкторов и тд. и тп.
template <class T> ostream& operator<< (ostream& out, list<T> ls) //неправильно почемуто ((( { /* term<T>* temp; temp = ls.h; while (temp) { out<<temp->data; temp = temp->next; } */ return *this; }
void main() { double a[5] = {1.7,2.3,3.4,4.5,5.7}; double b[7] = {7.0,6.4,5.5,4.6,3.7,2.8,1.3}; list<double> A(a, 5); cout<<A; //вот сдесь ошипка getch(); }
|
Ошибка такого содержания:
| Цитата | TemplateList error LNK2019: unresolved external symbol "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl operator<<(class std::basic_ostream<char,struct std::char_traits<char> > &,class list<double>)" (??6@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@std@@AAV01@V?$list@N@@@Z) referenced in function _main
|
Как перегрузить вывод с шаблонами??? Заранее спасибо  |