[C++-sig] newbie question: converting double* arrays

Andrew Straw strawman at astraw.com
Sat Jul 3 03:26:43 CEST 2004

Continuing the newbie questions:

I'm trying to call a C++ method which takes a double* as an argument.  
(I'm sure this isn't the best C++ style, but it isn't my library I'm 

After spending the day continuing up the Boost.Python and C++ learning 
curves, I've come up with the very non-ideal solution. It's particularly 
bad because even this hack doesn't compile! So, I seek feedback as to 
either 1) the Right Way to do it or 2) how to fix my presumably simple 

I know the function expects an array of 3 doubles, so I created this hack:

// ---- pyopencv.hpp
class Doubles3
  Doubles3(double a, double b, double c);
  double* Get();
  double values [3];

// ---- pyopencv.cpp
#include "pyopencv.hpp"
#include <boost/python/suite/indexing/vector_indexing_suite.hpp>
#include <boost/python.hpp>
#include <boost/python/numeric.hpp>
#include <boost/python/tuple.hpp>

Doubles3::Doubles3(double a, double b, double c) { values[0]=a; 
values[1]=b; values[2]=c; }
double* Doubles3::Get() { return values; }

using namespace boost::python;


  class_<Doubles3>("Doubles3", init<double,double,double>())

  class_<std::vector<double> >("vector_of_double")  // Could this be the 
start of the Right Way?
    .def(vector_indexing_suite<std::vector<double> >())

The error in this case is:
error: no
   match for call to `(const
   ) (double*)'

And if I try the other .def (commented out above), I get:
error: invalid
   application of `sizeof' to an incomplete type

So, I tried putting "double*" between () in 
return_internal_reference<>(), but this didn't help...  I'm in pretty 
deep into C++, as you can tell, but I should think this would be easy, 
even if it's not the best C++ style.  Please help!

For completeness' sake, here's what I'm trying to wrap:

// ---- original method I'm wrapping (in cvaux.h)
class CVAUX_DLL_ENTRY CvCalibFilter
    virtual bool
        SetEtalon( CvCalibEtalonType etalonType, double* etalonParams,
                   int pointCount = 0, CvPoint2D32f* points = 0 );

// ---- relevant snippet from boosst_cvaux.cpp
CvCalibFilter::SetEtalon, 2, 4)
  class_<CvCalibFilter, CvCalibFilterWrap, 
                                   "This is CvCalibFilter's docstring")

    .def("SetEtalon", &CvCalibFilter::SetEtalon,

More information about the Cplusplus-sig mailing list