Using void pointers for unknown return types in a linked list c++ -
i'm trying implement linked list , values held each node need not same type. i've used void pointer store value, issue i'm having retrieving value node. want write single function contains switch statement cast value appropriate type, i'm not sure how handle unknown return type other using void pointer.
is there way around this, or perhaps more efficient way handle unknown data types?
- you don't use
void*
unless you're 100% sure you're doing. - you don't use
t*
pointersvalue
- you don't use raw pointers @ all, appropriate idioms dynamic memory management facilities of c++ standard library.
- you use standard linked-list implementation:
std::list
.
"is there way around this, or perhaps more efficient way handle unknown data types?"
yes there's boost::any
or boost::variant
mentioned, though these aren't c++ standard types.
Comments
Post a Comment