fetch integer value from void pointer in cpp

12 Views Asked by At

i have below code use din one of project and value of members["Delay"] is modified in many places so at last just i wanted to print the value of members["Delay"] but i am unable to print the value with below code. Am I doing something wrong?

#include <iostream>
#include <typeinfo>
#include <map>
#include <memory.h>
using namespace std;


class TAnyMember
{
int a;
public:
void*   local;
int type;

public:
int operator = (int number)
{
    
    memcpy(&local,&number,sizeof(int));
    return number;
    
}

};

int main() {

    typedef map<std::string,TAnyMember> TTypedMap; 
    TTypedMap members;
    members["Delay"]            = 10;

    TAnyMember obj=members["Delay"];


    void* p = obj.local;

cout<<"beforecase"<<endl;
int* q = static_cast<int*>(p);

cout<<"after_case"<<endl;

cout << *q<< endl;
cout<<"print integer"<<endl;
return 0;
} 

i tried the above code and tried to assign the *q to int variable but it did not work

int* q = static_cast<int*>(p);
int value=*q;
0

There are 0 best solutions below