hetrogenous linked list,void pointers casting

September 20, 2011 at 12:35:28
Specs: Ubuntu, 3GB
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

See More: hetrogenous linked list,void pointers casting

Report •

#1
September 21, 2011 at 08:29:47
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.

How To Ask Questions The Smart Way


Report •

#2
September 21, 2011 at 09:53:48
can you give me the syntax of for C style casting?
Thanks for the reply.

Report •

#3
September 21, 2011 at 12:31:17
Sure?
someType someVar = (someType) someOtherVar;

How To Ask Questions The Smart Way


Report •

Related Solutions

#4
October 25, 2011 at 22:02:30
how do i cast a void pointer to int or char.The void pointer is declared as structure member.

Report •

#5
October 25, 2011 at 23:29:03
Why would you want to cast a void pointer to an integer? It doesn't seem to make sense in the situation you describe.

Report •

#6
October 27, 2011 at 08:22:20
//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

Report •

#7
October 27, 2011 at 09:49:44
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;

How To Ask Questions The Smart Way


Report •

#8
October 27, 2011 at 13:39:09
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.

Report •

Ask Question