Quantcast

C++ structure - no appropriate default constructor available

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

C++ structure - no appropriate default constructor available

schullq
I have this nested strucuture:

class Test
{
public:
        struct NestStruct
        {
            NestStruct(int st)
            {
                assert(st == READ || st == WRITE || st == DISABLED);
                value_ = st;
            }

            enum
            {
                READ,
                WRITE,
                DISABLED
            };

            operator bool() const
            {
                return value_ != DISABLED;
            }

            operator int() const
            {
                return value_;
            }

        private:
            int value_;

        };
[...]
};

And somewhere in the lib I try to wrap, i have this class with this constructor:

class MyClass
{
public:
      MyClass(RandomClass *cmd, Test::NestedStruct type);
[...]
};

The problem is that in the C wrapper code, this happens:

SWIGEXPORT void * SWIGSTDCALL CSharp_MyClass__SWIG_0___(void * jarg1, void * jarg2) {
  void * jresult ;
  RandomClassB *arg1 = (RandomClassB *) 0 ;
  Test::NestedStruct arg2 ;
  Test::NestedStruct *argp2 ;
  MyClass *result = 0 ;
  [...]
}

Swig tries to instanciate the struct, but there is no default ctor, and I don't know how to handle it...
Any help ?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: C++ structure - no appropriate default constructor available

schullq
Always on the same problem for a couple of days now, I think there is no solution to this.

The entire C wrapped code looks like this:

SWIGEXPORT void * SWIGSTDCALL CSharp_LibLogicalAccessfCard_new_MyClass__SWIG_0___(void * jarg1, void * jarg2) {
  void * jresult ;
  RandomClassB *arg1 = (RandomClassB *) 0 ;
  Test::NestedStruct arg2 ;
  Test::NestedStruct *argp2 ;
  MyClass *result = 0 ;
 
  arg1 = (RandomClassB *)jarg1;
  argp2 = (Test::NestedStruct *)jarg2;
  if (!argp2) {
    SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Attempt to dereference null Test::NestedStruct", 0);
    return 0;
  }
  arg2 = *argp2;
  result = (MyClass *)new MyClass(arg1,arg2);
  jresult = (void *)result;
  return jresult;
}

Actually, SWIG is trying to instantiate arg2, but it is useless, since it just return the jarg2 casts in (Test::NestedStruct *).

What is should do is erase this line:

  Test::NestedStruct arg2 ;

And replace those lines that way:

  result = (MyClass *)new MyClass(arg1,arg2);
[..]
  arg2 = *argp2;

by

  result = (MyClass *)new MyClass(arg1,*argp2);

Now, my problem is: how can I write this code manually ?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: C++ structure - no appropriate default constructor available

schullq
This post was updated on .
Well, shame on me.

It has finally worked. It seems that I just included the files in the wrong order...

My bad, swig handles it perfectly actually.
Loading...