Bill Spotz wrote:
> Suppose I have a C++ class MyClass, which has no default constructor.
> I also have a "factory" function that returns a pointer to a new
> std::vector<MyClass>, as well as a second function that takes a
> std:vector<MyClass> as an input argument. These are intended to work
> in tandem, ie, call the first function to get the vector, and use it
> as input to the second function.
> I used to do a
> %template () std::vector<MyClass>;
> in my interface file, which worked with older versions of swig. Now,
> the input argument to the second function has type __dummy_0__, and I
> get a
> NotImplementedError: No matching function for overloaded ...
> exception when I call it. I assume the newer versions of swig
> require that I give a name to that vector template in order for it to
> work in this particular case, so I changed the directive to
> %template (stdVectorMyClass) std::vector<MyClass>;
> But this results in a compiler error:
> /usr/include/c++/4.0.0/bits/stl_vector.h:219: error: no matching
> function for call to 'MyClass::MyClass()'
> because there is no default constructor. The wrapper code giving the
> error is in function
> SWIGINTERN PyObject *_wrap_new_stdVectorMyClass__SWIG_2(PyObject
> *SWIGUNUSEDPARM(self), PyObject *args)
> and the offending line of code is
> result = (std::vector<MyClass > *)new std::vector<MyClass >(arg1);
> The obvious solution to this seems to be to add an allocator to the %
> template directive, so that this last line doesn't try to access the
> non-existent default constructor. However, there is no obvious,
> simple allocator to use: the MyClass constructors take a class
> object as an argument, and there is no meaningful default value to use.
> The error here is really with a constructor for stdVectorMyClass,
> which I don't really want. I'm perfectly happy if the only way to
> create one of these is by calling the factory function I provide.
> How do I tell swig this is what I want?
> ** Bill Spotz **
> ** Sandia National Laboratories Voice: (505)845-0170 **
> ** P.O. Box 5800 Fax: (505)284-5451 **
> ** Albuquerque, NM 87185-0370 Email: wfspotz@... **
So that the methods which require a default constructor are not wrapped.