Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Return struct as void

Tags:

c++

structure

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*
like image 669
HariHaraSudhan Avatar asked May 03 '26 08:05

HariHaraSudhan


2 Answers

static_cast can convert void* to a pointer to a specific type:

widget_data* wd = static_cast<widget_data*>( yourVoidPointer );
like image 89
sharptooth Avatar answered May 05 '26 07:05

sharptooth


widget_data *wd=(widget_data *)GetObjectData();

or

widget_data *wd=reinterpret_cast<widget_data *>(GetObjectData());
like image 38
Sergey Teplyakov Avatar answered May 05 '26 05:05

Sergey Teplyakov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!