I am reading a double from the standard input and saving it into a variable d. I want to be able to do this an unspecified amount of times. I use the following code to create a pointer to d.
double *pd = new double;
pd = &d;
I then push this pointer into a constructed stack (list) class. But whenever I push more than one double it changes all of them (the pointer is the same).
Ex. push 2 and get an array [2]. push 3 and get array [3, 3] instead of [3, 2].
instead of
What you do is:
double dvariable on stackpdvariablepdon listThis means you have list of addresses to variable
d(every single object on list is pointer todvariable).