tonni
tonni

Reputation: 1255

void ** pointer in function argument c++

How to output variable of wchar_t * from void ** function argument in this situation?

I want to insert value of t in ChangeMe variable by using void**, how to accomplish that?

void foo(void **v){ wchar_t *t = L"String is changed!"; *(wchar_t*)v = *t; } 
wchar_t *ChangeMe = L"";

Try already (dont work):

foo((void**)ChangeMe );

Upvotes: 2

Views: 456

Answers (1)

πάντα ῥεῖ
πάντα ῥεῖ

Reputation: 1

You probably wanted to write

*((wchar_t**)v) = t; 

Note that t's value goes out of scope after return though. This may work in this case, because the literal's address has static storage duration.

Also when passing ChangeMe to the function you want to specify its address actually:

foo((void**)&ChangeMe);
         // ^

Here's the fully working sample.


Don't bother with void pointers; write proper C++ code.

Upvotes: 3

Related Questions