1 2 3 4 5
|
string *ptr1=new string, *ptr2=new string;
...
changePlace(*ptr1,*ptr2);
|
It's not clear from the function and parameter names what
exactly you intended to do here, but it is almost certainly not what you're doing.
To begin, you should not be newing these strings. You have a memory leak here since there is no possibility of freeing the memory you allocated after exiting the function.
Secondly, there are no changes made to vec. What you actually do is just swap *ptr1 with *ptr2 and discard both of those values when you leave replace.
What you you should do:
Find the position of a in the vec, if it exists.
Find the position of b in the vec, if it exists.
Swap the elements at those respective positions, if both exist.
You don't need pointers for any of that.