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

cPanel API
Hi Guys,

Need a little guidance. I'm trying to get my script to communicate with cPanel (or W

puting for loop in 1 value
hi ,

how do i put this code in 1 value:
Code: <?php
for ($i=1; $i<=5; $i

ASP.NET Validation Event Cycle
Hi,
I have asp button as follow:

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

newbie error
what is wrong with this code ?

<html>
<body>

<?

Preventing blank or already entered values
Im trying to learn how to place a read file line by line and prevent duplicate entries and also BLAN

Logic question
im wondering what's the best method to do the above list:

it is for alliance @ MMORPG game

Function to extract email attachments using PHP IMAP
function extract_attachments($connection, $message_number) {

$attachments = array();

Retreiving objects from Sessions
Hi all,

I am getting really frustrated with storing and retreiving objects from a session. Bu

Array help
Hello i got this code to fetch data from database but it is not working it displays
7
Array

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