I wrote a C++ template class, but I do not have the type to instantiate the class. Types are stored in a string format. So I have to do something like this:
if ( propType == "char") {
Property<char> pChar = ...
} else if ( propType == "int") {
Property<int> pChar = ...
} if ( propType == "double") {
Property<double> pChar = ...
}
I am not liking this if-else- loop, is there any way to avoid this, or any other solution to such problem?
Many ways, but it’s impossible to choose a good one without knowing how you use it in your particular case.
As a demonstration:
Property<T>classes inherit fromPropertyBaseHere is some code then:
Hope this helps.