4 ms·
It seems kind of stupid to use "-std=c++98" when building this stuff. Nothing in later Standards interferes with it. Maybe it is meant to serve notice that the
by ncmncm 5y ago
It seems kind of stupid to use "-std=c++98" when building this stuff. Nothing in later Standards interferes with it.
Maybe it is meant to serve notice that the method is archaic, and that better ways to achieve the same thing will be presented later. But then one might just as well code the throwaway examples in C and use a damn C compiler. It's archaic even for C. There is just no merit in storing a void* that will then be cast to some arbitrary other known type every time it is used.
The only really valid use for a void pointer is when it is being passed through a subsystem and comes back to somebody who knows what it is, such as when an abstract handler function is being registered along with a pointer to some context that will be passed to the handler; this is extremely common in C code.
In C++, you can just take a pointer to a type T with virtual member f() you promise to call. The caller supplies a pointer to T2 derived from T and with its own f(). This, too, feels a bit archaic, but is at least not actively silly.