Passing a template func. as a func. ptr to an overloaded func. - is there a way to compile this code
- by LoudNPossiblyRight
Just a general c++ curiosity:
This code below shouldn't compile because it's impossible to know which to instantiate: temp(const int&) or temp(const string&) when calling func(temp) - this part i know.
What i would like to know is if there is anything i can do to the line marked PASSINGLINE to get the compiler to deduce that i want FPTR1 called and not FPTR2 ?
#include<iostream>
using std::cout;
using std::endl;
/*FPTR1*/ void func(void(*fptr)(const int&)){ fptr(1001001);}
/*FPTR2*/ void func(void(*fptr)(const string&)){ fptr("1001001"); }
template <typename T>
void temp(const T &t){ cout << t << endl; }
int main(){
/*PASSINGLINE*/ func(temp);
return 0;
}
Thank you.