You should listen to Alf :) Here is my analysis: in a pure world, the identification of implementations threatens the polymorphism of virtual functions, it cannot and is not required.
In the dirty world of real programming, you may have some reasons for unique identification, such as marching data to disk, identifying diagnostic messages, monitoring control flow, collecting usage statistics, etc.
If your thoughts are clear, your design is wrong. Go away and find out why you cannot claim a unique identifier.
If your thoughts are distorted by reality, then you are ready to pay the price in performance and memory to meet your requirements, and then, according to the specification, using the built-in language features is worth paying, as this is largely the only way to achieve your goal of providing a non-invasive identification service. By non-invasive, I mean that you do not need to add anything to each derived class. Obviously, you need to add something, so if you do not want to do this, you have little choice but to accept what the compiler adds for you.
The main problem is that if you use dynamically loaded shared libraries (DLLS), RTTI may not work as expected. This not only affects typeid adversely, but it can also hinder the exception traps that you expect to receive (I was bitten!). Some help may be required to ensure that vtables and other RTTIs are uniquely created. This may mean, for example, that if the vtables binding to your destructor is not built-in, because in this case it can be generated in more than one place, which will destroy the uniqueness. Some hacks may be needed here in the absence of support for ISO standardization for dynamic loading.
Yttrill
source share