I\'m trying to create different objects of the same type using a loop, and then storing a pointer to each specific object in a linked list. The problem is, each time an object i
This line
cout<<&user<<endl;
prints the address of a pointer to an object. user
is itself a pointer to the object you're creating. To print the address of your object, you meant to write
cout<<user<<endl;
Although it'll be a new object each time, the variable user
is always in the same place. You can add the value of user
to your list, and it will indeed be different each time.
cout<<&user<<endl;
should be:
cout<<user<<endl;
&user is address of local variable Utilizador*, which remains the same. user variable value itself is the pointer you need, and it should be different on every iteration.
"&user" return address of pointer, that contains references to objects.