[C++-sig] implicit converter from enum to int problem

gideon may gideon at computer.org
Tue Aug 20 17:59:26 CEST 2002


Dear Dave,

I've been running into the same problem which Achim had regarding
the use of enumeration types (see 
http://mail.python.org/pipermail/c++-sig/2002-May/001077.html). He wasn't 
able to compile the code which you posted.
I tried something along the same line, which gave the following compiler 
error (osg::Material::Face is an enum):

C:\cvs_rep\boost\boost\boost\python\converter\implicit.hpp(43) : error 
C2440: '=' : cannot convert from 'int' to 'osg::Material:
:Face'
        Conversion to enumeration type requires an explicit cast 
(static_cast, C-style cast or function-style cast)
        C:\cvs_rep\boost\boost\boost\python\converter\implicit.hpp(28) : 
while compiling class-template member function 'void bo
ost::python::converter::implicit<Source,Target>::construct(PyObject 
*,boost::python::converter::rvalue_from_python_stage1_data *
)'
        with
        [
            Source=int,
            Target=osg::Material::Face
        ]

In the mail from may you mentioned that you forgot the rule for converting 
ints to enums. Has this been
implemented ?

I changed python/converter/implicit.h @ line 43 to the following :
        // new (storage) 
Target(*static_cast<Source*>(intermediate_data.stage1.convertible));
        new (storage) 
Target((Target)*static_cast<Source*>(intermediate_data.stage1.convertible));

and now I'm able to compile and run my code. Is it right what I did ? It 
seems to work for me.

ciao,

gideon




More information about the Cplusplus-sig mailing list