I am implementing hetrogenous linked list in C++.Inorder to take data from user i have taken a char array.Using isalpha() &isdigit() function i can identify the data type and convert to integer using atoi.But i`m unable to cast void pointer to that specific data type.I tried static_cast,reinterpret_cast but in compling it gives error.please help me type casting with syntax and any example if you could
The easiest way to cast in C++ is to just use a C style cast. It looks better, too. I tried static_cast,reinterpret_cast but in compling it gives error.
It's hard to tell what you're doing wrong without the code or error.
can you give me the syntax of for C style casting?
Thanks for the reply.
how do i cast a void pointer to int or char.The void pointer is declared as structure member.
Why would you want to cast a void pointer to an integer? It doesn't seem to make sense in the situation you describe.
//my struct definition is
struct node{
void *data;
struct node *next;
};
//now depending on the data type entered by user i want to cast void pointer
I should point out this node system is probably best handled by templates. Just cast your void* to the desired type.
int someInt = (int) someNode.data;
I think that you want to cast your pointer to a pointer to an int (or a char, or whatever), not an int. If you want to store different data types you would use a union.