Consider the following code:
#include <iostream>
This is a reduced but plausible representation of the problem.
Any derived class will have a specific, different identifier at runtime, and two instances of the same type will have the same identifier. Of course, this is a good solution to such a problem.
Unfortunately, these identifiers depend on the order in which the identifier members is called (we can easily see it by running the example several times). In other words, given the two classes A and B , if it happens that when you run the software twice, their identifier members are called in a different order, they have different identifiers.
My problem is that for some reason I need to store these identifiers somewhere and let them survive one execution, so that I can talk about the original types when the application starts again, and decide to read these values ββfrom storage.
An alternative would be to use hash_code from type_info , but it suffers from other problems. Another solution would be to force identifier members to run while the application is loading, but there are several drawbacks to this as well.
I would like to know if there is still an easy-to-use, although still elegant, solution completely transparent for the developer to identify types in several executions, since one of them refers to one application launch.
c ++ templates crtp
skypjack Nov 30 '15 at 21:13 2015-11-30 21:13
source share