Passing a template func. as a func. ptr to an overloaded func. - is there a way to compile this code

Posted by LoudNPossiblyRight on Stack Overflow See other posts from Stack Overflow or by LoudNPossiblyRight
Published on 2010-06-06T17:41:06Z Indexed on 2010/06/06 17:52 UTC
Read the original article Hit count: 316

Filed under:
|
|

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.

© Stack Overflow or respective owner

Related posts about c++

Related posts about templates