I wish to conditionally compile a function depending on the template type provided. I need to do so to overcome compile error
error: type 'double' cannot be used prior to '::' because it has no members T::myTypeFunction()
I have tried something like this:
1 2 3 4 5 6 7 8 9 10 11
template <class T>
void Foo(){
//[...] do something simple
if(typeid(T).name()==typeid(double).name()){
res = sizeof(double);
}
else {
res = T::myTypeFunction()
}
//[...] finish the simple task
}
which it actually works as soon as I do not call Foo<double>() or Foo<whatever non implementing ::myTypeFunction() for what it matters.
I do understand the problem is the compiler try to generate code for Foo<double> and produces the error because it cannot know runtime value for typeid(T).name()==typeid(double).name()).
Is there an elegant conditional compiling option can help solve this problem?
I do understand the problem is the compiler try to generate code for Foo<double> and produces the error because it cannot know runtime value for typeid(T).name()==typeid(double).name()).
I think the problem is actually this: res = double::myTypeFunction() That's the problem; trying to call a class member function on double.