U
Ulrich Hobelmann
Hi, I admit that this isn't great C++, but I'm reusing a container class
I wrote in C, which stores void * elements. Sometimes I insert pointers
into the container, sometimes ints (both are 32bit values, no problem).
Now I ported the thing to C++, and wrapped it in a template to get rid
of the while cast-to-void*/cast-from-void* mess. Works.
The problem is that I just tried to insert an int (i.e. instantiated the
template with something that's not a pointer), and my compiler (GCC 4) says:
In member function 'void List<T>::add(T) [with T = int]':
error: invalid conversion from 'int' to 'void*'
error: initializing argument 1 of 'void list::add(void*)'
(where: List<typename T> is wrapping my class "list")
Why can't i cast an int to void *? It's not pretty, but at least I'm
doing it explicitly, and no C dialect should get in my way
I wrote in C, which stores void * elements. Sometimes I insert pointers
into the container, sometimes ints (both are 32bit values, no problem).
Now I ported the thing to C++, and wrapped it in a template to get rid
of the while cast-to-void*/cast-from-void* mess. Works.
The problem is that I just tried to insert an int (i.e. instantiated the
template with something that's not a pointer), and my compiler (GCC 4) says:
In member function 'void List<T>::add(T) [with T = int]':
error: invalid conversion from 'int' to 'void*'
error: initializing argument 1 of 'void list::add(void*)'
(where: List<typename T> is wrapping my class "list")
Why can't i cast an int to void *? It's not pretty, but at least I'm
doing it explicitly, and no C dialect should get in my way