Input: if we want to allow several types of input, we can overload functions and methods
True
alternatively we can define a common base class.
This is partly true: what if you cannot define a common base class, interface, or the like? To determine which ones you need to access the source code, which is often not possible.
You did not specify patterns. However, templates cannot help you with polymorphism: they work with static types, that is, they are known at compile time.
void* can be considered the lowest common denominator. In C ++, you usually donβt need it, because (i) you cannot essentially do much with it, and (ii) there are almost always better solutions.
In addition, you should usually convert it to other specific types. This is why char * usually better, although this may indicate that you are expecting a C-style string rather than a clean data block. For this, void* better than char* for this, because it allows for implicit casting from other types of pointers.
You should receive some data, work with it and make a conclusion; To achieve this, you need to know the data you are working with, otherwise you have another problem that is not the one you originally solved. In many languages ββthere is no void* and, for example, there is no problem with this.
Other legal use
When printing pointer addresses with functions such as printf , the pointer must be of type void* and therefore you may need to cast to void *
edmz Dec 14 '15 at 17:22 2015-12-14 17:22
source share