How to convert void pointer to int/double/string pointer?

I have a function:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
const void insertStuff(const void *key, const int value){
  // I want to convert the void pointer into one 
  // of three types of pointers(int, string, or double)
  switch(value){
  case 0:
    int *intPtr = key;
    break;
  case 1:
    double *doublePtr= key;
    break;
  case 2:
    string *strPtr = key;
    break;
  }

}

But this causes an error of: "crosses initialization of int*intPtr"

What's the correct way of implementing this?
Last edited on
 
int *intPtr = (int *)key;
Topic archived. No new replies allowed.