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

Display the user's weight lost in the past week
Hello everyone,

I am working on a weight loss app for my site, and I want to display the user

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

Is there something wrong?
Hi all,

Just a quick question... can someone look at this code and see if something is wrong?

[Need Help] php timing issues
I don't know what is going wrong. I need some help with being able to set an image at 9:00am Colorad

A problem with my GD class
Hello,

I created a nice (and simple for now) GD class.
The problem is , it works great on

PHP Code To Change Font Color in Table Cell
I would appreciate help with the following snippet of my php code. I am just trying to change the f

calendar dates and hours compare problem
i have a calendar in wordpress, everything works great except that i can make 2 meetings at the same

my sql select id and then update problem.
I need to select some auto incremented ids out of a database and then use those id in a where statem

Post, not working, please help
The error is:
Method Not Allowed
The requested method POST is not allowed for the URL /student

ldap connection
We are using ldap to get user information from the domain controller. It was working before. Recentl

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