[bind] Overloaded function names
I have a function that performs the same task on several data types and data combinations: template <typename T> int f(const type1<T>& x); template <typename T> int f(const type2<T>& x); template <typename T> int f(const type2<T>& x, const type2<T>& y); I want to create a function object out of the second function. However, bind(f, _1) is ambiguous. Is there a way to disambiguate this using a bind call, or do I have to create my own function object? Thanks, Mark
Mark Ruzon escreveu:
I have a function that performs the same task on several data types and data combinations:
template <typename T> int f(const type1<T>& x);
template <typename T> int f(const type2<T>& x);
template <typename T> int f(const type2<T>& x, const type2<T>& y);
I want to create a function object out of the second function. However, bind(f, _1) is ambiguous. Is there a way to disambiguate this using a bind call, or do I have to create my own function object?
To take the address of an overloaded function you need to use static_cast to select the correct overload. The following program will compile. template <typename T> struct type1 { }; template <typename T> struct type2 { }; template <typename T> int f(const type1<T>& x) { return 0; } template <typename T> int f(const type2<T>& x) { return 0; } template <typename T> int f(const type2<T>& x, const type2<T>& y) { return 0; } int main (int argc, char* argv[]) { int (*ptr)(const type1<int>&) = static_cast<int (*)(const type1<int>&)>(&f); return ptr(type1<int>()); } -- Pedro Lamarão
participants (2)
-
Mark Ruzon
-
Pedro Lamarão