Possible Duplicate:
C++: Passing pointer variable to function
Here is a simplified code snippet which I think shows the problem at hand:
std::wstring *Variable3 = &SomeWStringObject; int _tmain(int argc, _TCHAR* argv[]) { std::wstring *Variable1 = NULL; func(Variable1); } void func(std::wstring *Variable2) { Variable2 = Variable3; } Now, in reality, func is a member of a class, and Variable3 is also a member of that same class. For this simpler example, let's just assume that Variable3 is some sort of global variable.
Variable3 is a (global variable) pointer to a std::wstring object. I can see in the debugger than it is pointing to the correct string.
What I want to end up with is Variable1 pointing to the same std::wstring object as Variable3.
So I tried passing the address of pointer Variable1 into the function, which I hoped would then set the address Variable3 points to into Variable1.
But this isn't working. It seems to be set OK, but then when the program leaves func, Variable1 is still a null pointer.
I have tried to be as clear as I can. I hope it is enough. Unfortunately, I cannot use the return value of func for this, as I actually have two other std::wstringstream objects to do the same thing to. Since all are having the same problem, I simplified it down to just one std::wstring object. I have tried lots of other different combinations of & and *, but none have worked.
Thank you very much for any help you can offer.
func) to be able to change the value of variables it was passed, use references: Declare it asvoid func(std::wstring *& Variable2).