[C++-sig] how to disambiguate 2 overloaded mem funs each with just 1 arg
David Abrahams
dave at boost-consulting.com
Sat Apr 1 20:50:43 CEST 2006
DRandallTaylor <DRandallTaylor at yahoo.com> writes:
> Hello,
> N00bie here.
> How do I disambiguate 2 member functions each having just 1 arg:
>
> struct C
> {
> int len(const char* const val) { return ::strlen(val); }
> int len(const std::string &val) { return val.size(); }
> };
> BOOST_PYTHON_MODULE(pycore)
> {
> boost::python::class_<C>("C")
> .def("len"
> , &C::len
> , boost::python::return_value_policy< python::return_by_value >()
> );
> }
>
> There must be some way to tell boost::python that when I pass a python str
> object to C::len then convert the arg to a "const char* const" and call the
> first overload of C::len. (I told you this was going to be easy! But not for
> me because I'm n00b.).
boost::python::class_<C>("C")
.def("len"
, (int (C::*)(char const*))&C::len
, boost::python::return_value_policy< python::return_by_value >()
);
HTH,
--
Dave Abrahams
Boost Consulting
www.boost-consulting.com
More information about the Cplusplus-sig
mailing list