void* and sizeof()


Posted on 16th Feb 2014 07:03 pm by admin

Hi,

Using void* and sizeof is it possible to get the value of the object ?

Did you know?Explore Trending and Topic pages for more stories like this.
I understand that dereferencing a void pointer is not directly possible. Is there a way (like casting) or something else to get the value of the object.

The problem is I wouldn't know the type of the object to cast to, I would only know the size of the object and a void pointer to the object.

something similar to what qsort does in stdlib.h, using merely the void pointer and sizeof, I think it manages to access the object, otherwise wouldn't be able to sort it.

Below shown is an example in which inside the function f1, I am suppose to access the object.

Code: class ClassA{};//Inside f1, I have to access the value of the object that pPtr1 points tovoid f1(void* pPtr1, const int pSizeOfObj){}int main(){ ClassA objA; f1(&objA, sizeof(objA)); return(0);}Thanks,
No comments posted yet

Your Answer:

Login to answer
324 Like 33 Dislike
Previous forums Next forums
Other forums

Help with writing "$" with fopen
I just can't get my syntax correct. Could someone help me please? I am trying to write a connect fil

Converting numbers to months
The porgram works -just need the last function(month_convert_ to convert numbers to months -thanks.

help with multi-update
Now sure how to ask this really....
10g database if that matters.

I have a customer

Multiple if statements
Ok so seems basic but for some reason I'm not doing it right. What I want is to be able to have 2 se

Oracle Connectivity
Hi Every One,

Can we access SAP from oracle database.If it possible then please spec

Creating XML with php
I need to creat an XML with php and have successfully produced a valid output.
The problem I hav

Solution Manager BPR
Does the SolMan-BPR-ARIS-Integration (http://www.ids-scheer.com/en/ARIS/ARIS_Platform/ARIS_Business_

How to update this array?
I am saving a string that looks this: username1, username2, username3...
into a single cell in a

problem with sql querry in php script
Hello guys,

What I want to do is I want to read out a csv file and then but te conent ot the

Extract specific information from a PHP Multidimensional Array
Howdy! I've racked my brain over this for 24 hours now. I think it's time I asked for help. I'm lear

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash