Patrick M. | 21 Nov 00:17

nested class workaround problem


Hello,
I tried the workaround for nested classes at 
http://www.swig.org/Doc1.3/SWIGDocumentation.html#SWIGPlus_nested_classes
(section 6.26, not exactly the example, see below), but I get the following
error when compiling the swig-generated test_wrap.cxx:

test_wrap.cxx: In function ‘PyObject* _wrap_Test_inner(PyObject*,
PyObject*)’:
test_wrap.cxx:2777: error: no matching function for call to
‘ns::Test::Inner::Inner()’

In my case the Inner class has no default constructor, but I thought swig
would recognize it and generate code that doesn't try to call Inner()
without arguments. How can I fix the problem?

I attach header and implementation test.h and test.cxx and the interface
file test.i:

--- test.h ---
namespace ns{
  class Test{
  public:
    class Inner{
    public:
      Inner(int arg);
    };
  private:
    Inner inner_;
  public:
(Continue reading)

Josh Cherry | 21 Nov 06:21
Favicon

Re: nested class workaround problem


On Thu, 20 Nov 2008, Patrick M. wrote:

> %module test;
>
> %include "test.h"
> 
> namespace ns{
> class Inner{
> public:
>   Inner(int arg);
> };
> }
> 
> %{
> #include "test.h"
> %}
> %include "test.h"
> 
> %{
> namespace ns{
>   typedef Test::Inner Inner;
> }
> %}

I presume it's unintentional that you %include test.h twice.  I suspect 
that the first %include is causing the problem.

Josh

(Continue reading)

Patrick M. | 21 Nov 09:38

Re: nested class workaround problem


Josh Cherry wrote:
> 
> I presume it's unintentional that you %include test.h twice.  I suspect 
> that the first %include is causing the problem.
> 

Correct. That was unintentional. I removed the first %include "test.h"
(right after %module test;), but the error remains the same.

I'd appreciate if somebody tried to compile this example (with the small
%include "test.h" correction) and suggests what is going wrong, or if the
problem is not reproducable.

For compilation, just put test.h, test.cxx and test.i in one directory and
run

$ swig -c++ -python test.i
>test.h:7: Warning(312): Nested class not currently supported (ignored).
$ g++ -c `python-config --includes` test_wrap.cxx
>test_wrap.cxx: In function ‘PyObject* _wrap_Test_inner(PyObject*,
PyObject*)’:
>test_wrap.cxx:2796: error: no matching function for call to
‘ns::Test::Inner::Inner()’
>test.h:6: note: candidates are: ns::Test::Inner::Inner(int)
>test.h:4: note:                 ns::Test::Inner::Inner(const
ns::Test::Inner&)

(I don't care about the nested class warning by swig, but I'm really hoping
to find a solution to the error
(Continue reading)


Gmane