Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#1268 feature code not inserted in default constructor

closed-invalid
python (258)
5
2012-12-10
2012-08-31
Michel Zou
No

Hi,
The feature code is not inserted in the default constructor:

%module example

%feature("pythonprepend") Foo::Foo() %{
print "prepend some code"
%}
%feature("pythonappend") Foo::Foo() %{
print "append some code"
%}

class Foo {
public:
Foo();
Foo(double x);
};

...whereas it works on the parameters constructors:
%feature("pythonappend") Foo::Foo(double) %{
print "append some code"
%}

I tried versions 2.0.4 and 2.0.8, same results.
Regards,
x.

Discussion

  • William Fulton
    William Fulton
    2012-12-10

    It does actually work with default constructors even though it seems that it does not. The reason is you have an overloaded constructor and it uses the feature from the first constructor parsed. There is only one Python proxy method for multiple C++ constructors and so there is no clear alternative approach. What I suggest you do is write your pythonprepend and pythonappend features for the generic constructor without specifying the constructor arguments, unless you have any other ideas? I've documented this in any case.

     
  • William Fulton
    William Fulton
    2012-12-10

    • assigned_to: nobody --> wsfulton
    • status: open --> closed-invalid