If I have a generic function that takes a void* as a parameter, can Auto in C++11 help stop any bad casting of that parameter?
For instance, we may have an event system that sends events and a pointer to some data that is relevant for the event it sends.
void EventClass::SendEvent (eventTypeEnum eventType, void* eventData) { int* castEventData = static_cast<int*> (eventData); //.. Do something } In the above example, one eventType could be sent with eventData as a float* and another as a pointer to a structure. The static_cast there will be mis-casting and causing problems.
Is there a way auto could be used to avoid this issue.
Please note, this is just an example (not a great one though sorry) to help me understand the possibilities of auto and not an actual issue I have.
eventTypeenum?autodeduces the type at compile time. What you need is deduction at run-time. One probable solution to your problem is to passboost::anyinstead ofvoid*.