test t = *tp; // I think the problem is here.
Yes you are right! Your code produces a copy, modifies it, and then quickly discards it.
Instead, you should change the structure passed through the pointer:
tp -> data = newData;
Pay attention to the operator ->. This is the equivalent of an access operator pointer .. It is equivalent
(*tp).data = newData;
but he looks better.
You can do the same in printData, although this is simply inefficiency:
cout << tp -> data;
source
share