![]() |
|
#1
|
|||
|
|||
dereferencing void pointerHi,
I have a void pointer. I am mallocing to it and cast it to appropriate type. However I am getting compiler errors about dereferecing void pointer. Following is the code CPP / C++ / C Code:
Compiler errors Quote:
Can anybody help me whats going wrong here? Thanks, |
|
#2
|
||||
|
||||
|
You can't dereference a void pointer, because it has an undetermined size. I only use those for returning undetermined types from functions, or storing undetermined data into a map (other people might make better use of them). To accomplish the task you set out for, you need something like this:
CPP / C++ / C Code:
Best regards, Lucian __________________
Please read these Guidelines before posting on the forum "A person who never made a mistake never tried anything new." Einstein |
|
#3
|
|||
|
|||
|
Hi Lucian,
Thanks for that tip. It worked. I am using void pointer because I want to use it to construct different types of packets in the same function, using packet type as handle. Each packet has different size which is not known in the begining. So I have to use void pointer for the packet and then cast it to appropriate packet type. Thanks, |
Recent GIDBlog
Developing GUIs with wxPython (Part 3) by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| shortest path algorithm and file saving | Pandiani | C++ Forum | 10 | 17-Jul-2006 10:46 |
| Opinion on my code and a c++ class question | FlipNode | C++ Forum | 7 | 07-Feb-2006 08:15 |
| [Tutorial] Pointers in C (Part I) | Stack Overflow | C Programming Language | 1 | 08-Apr-2005 18:35 |
| help with classes | bucho | MS Visual C++ / MFC Forum | 3 | 20-Oct-2004 06:16 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The