diff --git a/Examples/octave/operator/example.h b/Examples/octave/operator/example.h index 526f262b9..a9b69e009 100644 --- a/Examples/octave/operator/example.h +++ b/Examples/octave/operator/example.h @@ -30,7 +30,6 @@ public: double im() const { return ipart; } }; - - - - +ComplexVal operator*(const double &s, const ComplexVal &c) { + return ComplexVal(s*c.re(), s*c.im()); +} diff --git a/Examples/octave/operator/example.i b/Examples/octave/operator/example.i index ccb2029bc..7b903e69b 100644 --- a/Examples/octave/operator/example.i +++ b/Examples/octave/operator/example.i @@ -5,6 +5,9 @@ #include "example.h" %} +/* Rename friend operator */ +%rename(op_scalar_mul_ComplexVal) operator*(const double&, const ComplexVal&); + /* Now grab the original header file */ %include "example.h" @@ -20,5 +23,3 @@ return ComplexVal($self->re()*j,$self->im()*j); } }; - - diff --git a/Examples/octave/operator/runme.m b/Examples/octave/operator/runme.m index 2a4168660..85fd99ad4 100644 --- a/Examples/octave/operator/runme.m +++ b/Examples/octave/operator/runme.m @@ -22,3 +22,5 @@ printf("f = %s\n",disp(f)); # paren overloading printf("a(3)= %s\n",disp(a(3))); +# friend operator +printf("2*a = %s\n",disp(2*a)); diff --git a/Lib/octave/octrun.swg b/Lib/octave/octrun.swg index 2c36bc043..c2d2b0059 100644 --- a/Lib/octave/octrun.swg +++ b/Lib/octave/octrun.swg @@ -789,7 +789,7 @@ namespace Swig { octave_value fcn = get_global_value(symbol, true); if (!fcn.is_function() && !fcn.is_function_handle()) return false; - ret = fcn.subsref("(", std::list < octave_value_list > (1, args)); + ret = fcn.subsref("(", std::list < octave_value_list > (1, args), 1); return true; }