Boost logo

Boost Users :

Subject: [Boost-users] boost::function unusable as overloadable function argument
From: Peter Soetens (peter.soetens_at_[hidden])
Date: 2009-08-27 11:55:18


Hi,

I had this situation in a bigger program, where a user could supply a
string or a function object:

<code>
#include <boost/function.hpp>
#include <string>

void foo1(int i, std::string a);
void foo1(int i, boost::function<void(void)> foo );

int main(int argc, char** argv)
{
  //boost::function<void(void)> foo = "hello"; // this line won't compile

  foo1( 3, "hello" ); //error: call of overloaded ‘foo1(int, const
char [6])’ is ambiguous

  return 0;
}
</code>

Although constructing a boost::function from a C string is nonsense,
the compiler does consider it as an alternative when trying to find
the right foo1. Is there any work around to keep the overloads without
requiring the user to write
foo1(3, string("hello")); or is this a compiler bug (g++ (Ubuntu
4.3.3-5ubuntu4) 4.3.3)?

Thanks for any insights,
Peter


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net