I got an overloaded function:

void f(int n)
{
  std::clog << "invoked f(int n = " << n << ")" << std::endl;
}

void f(double d)
{
  std::clog << "invoked f(double d = " << d << ")" << std::endl;
}

If I put declarations in that order:

void (*f_int)(int) = &f;
void (*f_double)(double) = &f;

BOOST_PYTHON_MODULE(test)
{
  def("f", f_int);
  def("f", f_double);
}

No matter what I pass into the function f, f(double) is invoked every time. 
Even though I call f(int(1)) I will see "invoked f(double d = 1)".

But if I declare the function f in reversed order:

BOOST_PYTHON_MODULE(test)
{
  def("f", f_double);
  def("f", f_int);
}

I will see "invoked f(int n = 5)" when I call f(5) and "invoked f(double d = 
3.14)" when I call f(3.14) as it has to be. Why does it happen? Why does it 
depend on declaration order?

-- 
Ilya.
_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig@python.org
https://mail.python.org/mailman/listinfo/cplusplus-sig

Reply via email to