Hi, I have this porgram where I need to convert a python float in to C++ class object and for that I am using implicitly_convertible In the porgram below (a very simple one) the constructor takd two arguments and when I compile with that I got this error .. c:\users\aashish\boost-1.30.2\boost\python\converter\implicit.hpp(34): error C2664: 'PlotVariableTable::PlotVariableTable(const PlotVariableTable &)' : cannot convert parameter 1 from 'const double' to 'const PlotVariableTable &' Now when I compiled and tested with the constructor taking only a single value (and hence changed some lines accordingly) program just worked fine. Please let know is someone can help me as soon as possible. Thanks, Aashish #include <boost/any.hpp> #include <boost/python.hpp> #include <boost/python/extract.hpp> #include <boost/python/dict.hpp> #include <boost/any.hpp> #include <boost/python/implicit.hpp> #include <boost/python/module.hpp> #include <cstdio> #include<iostream> //#include <PlotVariableTable.h> using namespace boost::python; namespace bp = boost::python; class PlotVariableTable { public: /** * Default Constructor * * @param cols number of columns in the table */ PlotVariableTable(double rows, double cols):v(rows), v1(cols){} double v, v1; }; PlotVariableTable make_x(double n, double n1) { PlotVariableTable a = PlotVariableTable( n , n1); return a; } BOOST_PYTHON_MODULE(hello) { def("make_x",make_x); class_<PlotVariableTable>("PlotVariableTable",init<double, double>()); implicitly_convertible<double,PlotVariableTable>(); }
"aashish" <aashish@vrac.iastate.edu> writes:
I have this porgram where I need to convert a python float in to C++ class object and for that I am using implicitly_convertible
In the porgram below (a very simple one) the constructor takd two arguments and when I compile with that I got this error ..
c:\users\aashish\boost-1.30.2\boost\python\converter\implicit.hpp(34): error C2664: 'PlotVariableTable::PlotVariableTable(const PlotVariableTable &)' : cannot convert parameter 1 from 'const double' to 'const PlotVariableTable &'
Now when I compiled and tested with the constructor taking only a single value (and hence changed some lines accordingly) program just worked fine.
Please let know is someone can help me as soon as possible.
A single-argument constructor that is not marked "explicit" makes the argument type convertible to the class type. Without that, a double is not implicitly convertible to a PlotVariableTable. implicitly_convertible requires that its first argument is convertible to its second argument. These are just C++ rules; and have nothing to do with Boost.Python. -- Dave Abrahams Boost Consulting www.boost-consulting.com
Hi, This might be a very simple question but I am wondering when I should use implicitly_convertible as I found that in certain cases the coversion from Python type to C++ type is possible without using it. Thanks, Aashish -----Original Message----- From: c++-sig-bounces@python.org [mailto:c++-sig-bounces@python.org] On Behalf Of David Abrahams Sent: Monday, January 19, 2004 11:17 AM To: c++-sig@python.org Subject: [C++-sig] Re: implicitly_convertible "aashish" <aashish@vrac.iastate.edu> writes: A single-argument constructor that is not marked "explicit" makes the argument type convertible to the class type. Without that, a double is not implicitly convertible to a PlotVariableTable. implicitly_convertible requires that its first argument is convertible to its second argument. These are just C++ rules; and have nothing to do with Boost.Python. -- Dave Abrahams Boost Consulting www.boost-consulting.com _______________________________________________ C++-sig mailing list C++-sig@python.org http://mail.python.org/mailman/listinfo/c++-sig
"aashish" <aashish@vrac.iastate.edu> writes:
Hi,
This might be a very simple question but I am wondering when I should use
implicitly_convertible as I found that in certain cases the coversion from Python type to C++ type is possible without using it.
implicitly_convertible isn't there just to enable Python->C++ conversions. Many built-in conversions work automatically. if there exists a conversion from Python type P -> C++ type C implicitly_convertible<C,D>(); will enable a conversion from Python type P -> C++ type D -- Dave Abrahams Boost Consulting www.boost-consulting.com
Hi, Well as I posted some problems before regarding boost.python project file for the Windows ...as when I didn't make it I started compiling myself using MSVC 7.0 and it came out fime but just one error (well some more and they all belongs to this line) In the header file: Function_trmplate.hpp this->manager = &detail::function::trivial_manager<FunctionObj>; c:\users\aashish\learning\software\boost-1.30.2\boost\function\function_temp late.hpp(511) : error C2563: mismatch in formal parameter list c:\users\aashish\deere6\learning\software\boost-1.30.2\boost\function\functi on_template.hpp(511) : error C2568: '=' : unable to resolve function overload c:\users\aashish\deere6\learning\software\boost-1.30.2\boost\function\functi on_base.hpp(192): could be 'boost::detail::function::any_pointer boost::detail::function::trivial_manager(boost::detail::function::any_pointe r,boost::detail::function::functor_manager_operation_type)' Any help will be appreciated.. Thanks, Aashish
My guess is that this is a secondary error and the real problem is somewhere else. Could you try to strip down your code to a minimum and then post the remaining rest, along with the command line that you use for compiling? Ralf --- aashish <aashish@vrac.iastate.edu> wrote:
Hi,
Well as I posted some problems before regarding boost.python project file for the Windows ...as when I didn't make it I started compiling myself using
MSVC 7.0 and it came out fime but just one error (well some more and they all belongs to this line)
In the header file:
Function_trmplate.hpp
this->manager = &detail::function::trivial_manager<FunctionObj>;
c:\users\aashish\learning\software\boost-1.30.2\boost\function\function_temp late.hpp(511) : error C2563: mismatch in formal parameter list
c:\users\aashish\deere6\learning\software\boost-1.30.2\boost\function\functi on_template.hpp(511) : error C2568: '=' : unable to resolve function overload
c:\users\aashish\deere6\learning\software\boost-1.30.2\boost\function\functi on_base.hpp(192): could be 'boost::detail::function::any_pointer boost::detail::function::trivial_manager(boost::detail::function::any_pointe r,boost::detail::function::functor_manager_operation_type)'
Any help will be appreciated..
Thanks, Aashish
__________________________________ Do you Yahoo!? Yahoo! Finance: Get your refund fast by filing online. http://taxes.yahoo.com/filing.html
Hi, I wanted to have a function like this where when I pass a list I will either get return as set of integers or std::vector of double. I tried to implement the function in this manner ..... C++-------------------------------- int make_vector(bp::list vlist) { //std::vector<double> vector_list; int k = extract<int>(vlist.attr("__len__")()); /*for (int i=0;i<10;i++) { vector_list.push_back(extract<double>(lt.attr("__getitem__")(i))); } return vector_list;*/ int kk = extract<int>(vlist.attr("__getitem__")(0)); return kk; } Python----------------------------- L = ['1','2','3'] a = make_vector(L) print a The problem is that I am getting the correct value for 'k' here but then it does throws error saying that Tracekack(most recent call last) File "pytest2.py" , line 30, in ? A = "make.vector"(L) Typeerror: No registered converter was able to produce a C++ rvalue of type int from this Python object of type str. Now what does this error mean?? And How can sole this problem. Thanks. ~regards, Aashish
"aashish" <aashish@vrac.iastate.edu> writes:
Hi,
I wanted to have a function like this where when I pass a list I will either get return as set of integers or std::vector of double.
I tried to implement the function in this manner .....
C++-------------------------------- int make_vector(bp::list vlist) { //std::vector<double> vector_list; int k = extract<int>(vlist.attr("__len__")());
/*for (int i=0;i<10;i++) {
vector_list.push_back(extract<double>(lt.attr("__getitem__")(i)));
That's the hard/ugly way. Why not: vector_list.push_back(extract<double>(lt[i])); ??
}
return vector_list;*/
int kk = extract<int>(vlist.attr("__getitem__")(0));
return kk; } Python-----------------------------
L = ['1','2','3'] a = make_vector(L) print a
The problem is that I am getting the correct value for 'k' here but then it does throws error saying that
Tracekack(most recent call last) File "pytest2.py" , line 30, in ? A = "make.vector"(L) ^^^^^^^^^^^^^ I can't believe that you copied this error message correctly.
Typeerror: No registered converter was able to produce a C++ rvalue of type int from this Python object of type str.
Now what does this error mean??
The error means that you tried to extract<int> from a Python string object.
And How can sole this problem.
Store ints instead of strings in L L = [ 1, 2, 3 ] ?? -- Dave Abrahams Boost Consulting www.boost-consulting.com
participants (3)
-
aashish -
David Abrahams -
Ralf W. Grosse-Kunstleve