mitrmkar
Posting Virtuoso
1,809 posts since Nov 2007
Reputation Points: 1,105
Solved Threads: 395
If you want to get to the data that a pointer to void points to, you need to cast it into the correct type first:
#include <iostream>
int main()
{
using namespace std;
int x = 3;
float y = 2.35f;
char c = 'A';
void *ptr;
ptr = &x;
cout<< *static_cast<int*>(ptr) <<'\n';
ptr = &y;
cout<< *static_cast<float*>(ptr) <<'\n';
ptr = &c;
cout<< *static_cast<char*>(ptr) <<'\n';
}
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401