[C++-sig] Re: Boost.Python not resolving overloads

David Abrahams dave at boost-consulting.com
Sun Sep 21 03:46:46 CEST 2003


"Niall Douglas" <s_sourceforge at nedprod.com> writes:

>>>> 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).

> 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.  

  The Zen of Python, by Tim Peters

  Beautiful is better than ugly.
  Explicit is better than implicit.
  Simple is better than complex.
  Complex is better than complicated.
  Flat is better than nested.
  Sparse is better than dense.
  Readability counts.
  Special cases aren't special enough to break the rules.
  Although practicality beats purity.
  Errors should never pass silently.
  Unless explicitly silenced.
  In the face of ambiguity, refuse the temptation to guess.
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  There should be one-- and preferably only one --obvious way to do it.
  Although that way may not be obvious at first unless you're Dutch.
  Now is better than never.
  Although never is often better than *right* now.
  If the implementation is hard to explain, it's a bad idea.
  If the implementation is easy to explain, it may be a good idea.
  Namespaces are one honking great idea -- let's do more of those!

It works just the same way Python does.  If that's not intuitive
enough for you, you should take it up with Guido!

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com





More information about the Cplusplus-sig mailing list