#include <iostream>
#include <string>
#include <vector>
#include <cmath>
using namespace std;
template <typename T>
class Lista
{
public:
struct Item
{
T wartosc;
Item *next;
};
Item *first;
public:
Lista();
~Lista();
Lista<T> & operator<<(T i);
};
template <typename T>
Lista<T>::~Lista()
{
Item *element = first;
while(element)
{
Item *nastepny = element->next;
delete element;
element = nastepny;
}
}
template <class T> Lista<T> & Lista<T>::operator<<(T i)
{
Item *nowy = new Item;
nowy->wartosc = i;
nowy->next = NULL;
Item *tmp = first;
while(tmp->next != NULL)
{
tmp = tmp->next;
}
tmp->next = nowy;
return *this;
}
int main()
{
Lista<int> L1();
L1<<2;
cin.get();
cin.get();
return 0;
}
Czemu instrukcja dodania 2 do listy kończy się niepowodzeniem?