[C++-sig] enums and structs

David Abrahams david.abrahams at rcn.com
Sun May 19 19:35:17 CEST 2002


----- Original Message -----
From: "Achim Domma" <achim.domma at syynx.de>
> > -----Original Message-----
> > From: c++-sig-admin at python.org [mailto:c++-sig-admin at python.org]On
> > Behalf Of David Abrahams

> > Uhh... well, I guess that's what you'd need to do, until the new
interface
> > is implemented. However, it's pretty easy to get the from_python
> > converters
> > (http://www.boost.org/libs/python/doc/v2/implicit.html):
> >
> >     implicitly_convertible<int, my_enum_type>();
>
> Because I only pass enums to functions, conversion from enum to int
should
> be enough. It works for me, if I use
>
> implicitly_convertible<my_enum_type, int>();
>
> which makes sense to me,

Not to me; you really should trust that I know what I'm writing (and look
at the docs and examples if you have second thoughts).

> because I convert enum to int and not the other
> way. Am I right?

No. It's the library which must do the conversion. When it's trying to
match an argument of my_enum_type, it looks for conversions which can
produce int, because it knows int is convertible to my_enum_type. That's
why you should write it the way I did.

> But now I get my next error:
>
> E:\cvsroot\boost\boost/python/detail/arg_tuple_size.hpp(83) : error
C2665:
> 'arg_tuple_size_helper' : none of the 4 overloads can convert parameter 1
> from type 'void (__thiscall Magick::Image::*)(const
MagickLib::NoiseType)'
>         E:\cvsroot\boost\boost/python/make_function.hpp(26) : see
reference
> to class template instantiation
'boost::python::detail::arg_tuple_size<void
> (__thiscall Magick::Image::*)(enum MagickLib::NoiseType)>' being compiled
>         E:\cvsroot\boost\boost/python/detail/wrap_function.hpp(30) : see
> reference to function template instantiation 'struct
> boost::python::objects::function *__cdecl
boost::python::make_function(void
> (__thiscall Magick::Image::*)(const MagickLib::NoiseType))' being
compiled
>
> NoiseType is an enum which I made available via
>
> implicitly_convertible<MagickLib::NoiseType,int>();
>
> and the function where the problem occures is defined as
>
> class_<Magick::Image> wrapper_of_Image("Image");
> //...
> wrapper_of_Image
> //some ctors ...
> .def_init(...)
> .def("addNoise",(void (Magick::Image::*)(const
> NoiseType))&Magick::Image::addNoise)
> //...
>
> I tried to look to the code, but I failed to understand what the
> 'sizeof-Magic' in arg_tuple_size.hpp is good for and how it works. Any
hint
> what's going wrong?

Well, this is a VC bug: the argument type is not "const NoiseType", but
simply "NoiseType" - writing const on a function parameter is not supposed
to change the type of the function, only how the parameter behaves within
the definition - though it *does* change the function type in VC. In fact:

void f(int); // declaration
void f(int const x) {} // definition of the same function

So leave off the "const" and you'll be fine.

-Dave







More information about the Cplusplus-sig mailing list