0

I have a void pointer which contains the address of object but I do not which types of this object. My code is like

VARIANT vtProp;

Now getting the value in vtProp using some method. It's have successfully some values.

Now I have assign the value in void pointer

void *ptr = vtProp.pparray;

Now it is getting the some array of object. I need to get the object from the void pointer but when I was displaying the value in void pointer using

wcout << ptr << endl;

It is only displaying the address contains in void pointer.

Could you please suggest me how to print the object name.

user2499879
  • 673
  • 3
  • 10
  • 16

1 Answers1

0

This prints an address:

void *ptr = vtProp.pparray;
wcout << ptr << endl;

because the overload of operator<<, which takes void* is applied. In case ptr points to an object that has a member name, you should do:

MyObject* ptr = reinterpret_cast<MyObject*>(vtProp.pparray);
wcout << ptr->name << endl;
LihO
  • 41,190
  • 11
  • 99
  • 167
  • :Thanks for your reply. But I do not know, which types of object is retruning. so, How can I type cast. – user2499879 Oct 07 '13 at 10:30
  • @user2499879: How do you want to use the contents of that memory block if you don't know what is stored there? The pointer to this memory would be completely useless in that case. – LihO Oct 07 '13 at 10:31