Heh, thanks!
Line 20
Yes, template functions are really just instructions to the compiler on how to make a function. No function actually exists until you use it, but you still must declare it before using it.
You could have declared it before your import function (lines 125..126) and it would work.
Lines 15, 16, 17, etc
You don't actually have to keep saying 'struct' in C++. The definition on line 8 is enough. Elsewhere you can just say:
1 2 3 4 5
|
Dati *creaLista();
void stampaLista(Dati *);
...
foo = new Dati;
...
|
Line 44, 45
I think you are still a little fuzzy on pointers. Again I recommend you to the tutorials on this site.
On line 44, you create a new
Dati on the heap and put its address in the variable
lista.
Then, on line 45 you use
creaLista() to create
new Datis on the heap and put the first one's address in the variable
lista.
What has happened is that the address of the
Dati you allocated on line 44 is forgotten, so you can never access it again. This is a memory leak.
Since you don't need the
Dati on line 44, just get rid of line 44 altogether.
(BTW, "lista" is a terrible name for a list. You should name things based on what they contain, not on what they are. Better names might be "dati_della_gente" or "dati_degli_amici" or etc)
Line 79
This is why it breaks. You have a malformed list.
I could tell you exactly how to fix it, but I think you would benefit more by figuring it out yourself. Personally, I find that getting out a piece of paper and drawing little boxes labeled "first element", "second element", etc. and drawing little arrows between the boxes helps me a lot.
Again, "pointer" is a terrible name. A better name would be "dati_prossimo" or even just "prossimo".
Other commentary
Your print list function looks great!
In your save function you don't need to close and reopen the file. The
ios::trunc does everything you need. (So you can delete lines 114 and 115.)
The import function has the same problem as the create list function.
Also, don't put spaces in the keyname to look for. In other words, say
"Nome:" instead of
"Nome: ". The >> operator stops reading at whitespace, so the second version can never match.
You seem to have a very good understanding of things. Keep up the great work!
I'd love to visit Italy, but I probably wouldn't get past airport security because I'd mangle your language like a Mexican. :-S :-)