[C++-sig] Re: Boost.Python not resolving overloads
Niall Douglas
s_sourceforge at nedprod.com
Sun Sep 21 04:06:09 CEST 2003
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 20 Sep 2003 at 21:46, David Abrahams wrote:
> >>>> from TnFOX import *
> >>>> fh=FXFile("fred.txt")
> >>>> print fh.name()
> > Traceback (most recent call last):
> > File "<stdin>", line 1, in ?
> > Boost.Python.ArgumentError: Python argument types in
> > FXFile.name()
> > did not match C++ signature:
> > name(class FX::FXString)
> > name(class FX::FXFile {lvalue})
> >>>> print fh.name(fh)
> > fred.txt
> >
> > As it says, there are two name()'s defined.
>
> Clearly it's a static method which takes a single argument. if you
> want to call it as fh.name() you can't make it static (or you need an
> overload which takes no arguments).
Yes sorry - it's 3am here. One of the name()'s is static but the
other one isn't:
class FXFile
{
const FXString &name() const;
static FXString name(const FXString &file);
};
Now in my example above, I was calling name(void), not name(file). If
you call name(fh) then it correctly calls the name(void).
> > I tried a number of other
> > functions with no parameters and all of them cause an error if there
> > are overloads present. The only way to make them work is to include
> > the instance as the first parameter.
> >
> > Is this right? It's counter-intuitive and inconvenient - surely
> > boost.python can try inserting the instance if no parameters are
> > present?
>
> Wha??? No, it can't just guess at what you mean.
I don't see why. If one of my name()'s is zero parameters and the
other one takes a string, and I call name(), then it's obvious I want
the zero parameter one.
Besides, the error message is from Boost.Python, not Python.
If this is not known behaviour, I'll make you a demo though it would
be trivial for you to write yourself.
Cheers,
Niall
-----BEGIN PGP SIGNATURE-----
Version: idw's PGP-Frontend 4.9.6.1 / 9-2003 + PGP 8.0.2
iQA/AwUBP20HkcEcvDLFGKbPEQIAuQCfYg5xUp1xXmR2fgrHDfErGccMHeoAoJRD
9VEDNekkWKakxg2DE2gxYc9n
=g+T/
-----END PGP SIGNATURE-----
More information about the Cplusplus-sig
mailing list