[C++-sig] question on object section of bpl tutorial

Nicodemus nicodemus at globalite.com.br
Thu Dec 12 12:46:36 CET 2002

Mark Russell wrote:

>The compiler cannot resolve the str ambiguity--I did some research on this
>and I guess my compiler is one of the broken ones that can't do this
>automatically :{  I have made several tries at explicitly specifying the
>name but no joy--how do I do this?  --Mark

Hi Mark,

I have the same problem, unfortunately (Intel C++ 6.0). I assume that 
you're doing a 'using namespace boost::python' at the top of the module.

So, there's two cases where you can use str:

1) When you are dealing with a PyString:

str x( "Hello"  );

To solve this, simply preppend 'boost::python::':

boost::python::str x( "Hello" );

2) When you're exporting the __str__ method:

.def( str(self) )

To solve the ambiguity, preppend 'boost::python::self_ns::' (or just 

.def( boost::python::self_ns::str(self) )
.def( self_ns::str(self) )

Hope this helps.

More information about the Cplusplus-sig mailing list