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 ?

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

Comparing Values
Hi
I'm reading data from a database and this seems to work OK.

Each system has an associat

Syntax error
hi im having a little trobble with this script
-------------------------------------------------

Help on code output
My CODE:

Code: [Select] echo "<phone>".$line["phone"].&qu

grouping within a foreach?
hello all,

I currently have a list of products spit out from my db via a foreach loop. Right

PHP code for a proxy
I was wondering which function I could use to create an online proxy tool. I was thinking cURL would

ereg_replace issue
hi there people

i have this code happening with regards to my wamp server. is this something

The page should be expire when cilck back button
hi,
i'm new to php world.
i create user registration page.
when i submit it,data goes to my

PHP webpage & array print issue
I have this code running, and it works perfectly … however, see my bottom bit about what I see

include function being weird?
I have a very simple system to grab an IP outputted by a PHP file.. (for a project I have) but it ou

SESSION CHECK WORKS "MOST" of the time... whats going on?
i have a sign in check thats included in every page that is a members only page which is basically a

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