I’m having a function that returns a a void data. And i need to receive it as a structure.
eg. say a structure widget_data. a function GetObjectData() that returns a void data.
widget_data *wd=GetObjectData();
and GetObjectData() returns sd->data.
where sd is structure, data is of void type.
when i compile it i get error message like
invalid conversion from void* to widget_data*
Let’s clarify things a little first.
voidmeans nothing, so you cannot have a data of void type. Thus, if function returnsvoidthen is cannot possibly return any data. Now, thevoid *is a void pointer. You can treat it as a memory address pointing somewhere. It could be pointing to any kind of data, or even nowhere. If you are pretty sure that your function returns a pointer towidget_dataobject, then you can do a reinterpret_cast. For example:If you are not that sure, you have to check the type of data returned. That might be possible if RTTI is enabled (it is usually enabled by default) and base class has at least one virtual method. Then you can use dynamic_cast. If that is not possible, you have to come up with some custom way of checking the return type.