[C++-sig] Weird function call results
Stefan Seefeld
stefan at seefeld.name
Fri Dec 19 14:34:45 CET 2014
On 18/12/14 06:13 AM, ilias wrote:
> 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?
It definitely shouldn't. If it does, please submit a bug report
including the test, as well as details as to what compiler and OS you
were observing the error on.
Thanks,
Stefan
--
...ich hab' noch einen Koffer in Berlin...
More information about the Cplusplus-sig
mailing list