[C++-sig] question about implicit type conversion of vector to a custom type

Grant Tang grant.tang at gmail.com
Tue Aug 16 21:43:10 CEST 2011


This is a question about using implicitly_convertible to convert vector to
another custom class type.

I already have boost python type conversion code to convert Python
list/tuple to c++ vector, which works fine. There is another custom class
EMObject, which is a thin wrapper to many builit-in type. It takes a
built-in type like int, float, string, and vector as a single constructor
argument and return type. So those built-in type can convert to and from
EMObject implicitly. The functions in c++ which takes this EMObject as an
argument are expose to Python. Now I need call these functions in Python
with argument from Python list or tuple. Since I already convert python
list/tuple to c++ vector, I just need declare implicit type conversion from
vector to EMObject like following:

implicitly_convertible<vector<float>, EMAN::EMObject>();
implicitly_convertible<vector<int>, EMAN::EMObject>();
implicitly_convertible<vector<std::string>, EMAN::EMObject>();

This seems a perfect solution to my question. But unfortunately I find out
only the first one working, regardless which one is the first. Could anybody
tell me why this happen?

-- 
Grant
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20110816/69455f46/attachment.html>


More information about the Cplusplus-sig mailing list