Quantcast

override c++ constructor

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

override c++ constructor

Aaron Knister
I've spent quite a bit of time trying to figure out how to do this and
I'm coming up short.

I've got a C++ class where the first argument of the constructor is a
pointer to a typdef'd struct that is used to return an error code.
Something like this:

class MyClass {

        MyClass(errStruct *errP, arg1, arg1 )

}

I can't figure out how to tell swig that errP is an OUTPUT parameter.  I
naively tried this based on the SWIG example:

extern MyClass::MyClass(errStruct *OUTPUT, arg1, arg2);

but compilation gives me this:

error: declaration of ‘MyClass::MyClass(errStruct*, arg1, arg2)’ outside
of class is not definition

any ideas on how I can do this?

Thanks!

-Aaron

--
Aaron Knister
NASA Center for Climate Simulation (Code 606.2)
Goddard Space Flight Center
(301) 286-2776

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Swig-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swig-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: override c++ constructor

Bob Hood
On 2/20/2017 10:28 AM, Aaron Knister wrote:

> I've spent quite a bit of time trying to figure out how to do this and
> I'm coming up short.
>
> I've got a C++ class where the first argument of the constructor is a
> pointer to a typdef'd struct that is used to return an error code.
> Something like this:
>
> class MyClass {
>
> MyClass(errStruct *errP, arg1, arg1 )
>
> }
>
> I can't figure out how to tell swig that errP is an OUTPUT parameter.  I
> naively tried this based on the SWIG example:
>
> extern MyClass::MyClass(errStruct *OUTPUT, arg1, arg2);
>
> but compilation gives me this:
>
> error: declaration of ‘MyClass::MyClass(errStruct*, arg1, arg2)’ outside
> of class is not definition
>
> any ideas on how I can do this?

Well, doing output arguments from a constructor seems kind of weird.  You
might want to consider making that a method call instead:

    MyClass klass(arg1, arg2);
    const errStruct* errP = klass.getErrStruct();

I was going to suggest that perhaps the "%typemap(argout)" directive might be
of use here, which is intended for use in returning output arguments, but I
doubt it was designed to function on a constructor:

http://www.swig.org/Doc2.0/SWIGDocumentation.html#Typemaps_nn32


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Swig-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swig-user
Loading...