help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Calling a method of an object?


From: Joanna Rutkowska
Subject: Calling a method of an object?
Date: Thu, 18 Oct 2012 19:30:25 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20120911 Thunderbird/15.0.1

Hello, I've created a simple class:

function m = motor (name, Kv, Rm, I0)
        m.name = name;
        m.Kv = Kv;
        m.Rm = Rm;
        m.I0 = I0;
        m = class (m, "motor");
end

...and one simple method:

function power = power_out (motor, u, i)
        power = (u - i*motor.Rm) * (i - motor.I0);
end

... and I created an object of the class motor:

octave:1> m1 = motor ("Sample motor", 400, 0.05, 1);

... but I cannot call the power_out method using the traditional "OO way":

octave:2> m1.power_out (1,1);
error: invalid index for class

... only this form seems to work:

octave:2> power_out (m1, 1, 1);

Is it how this is supposed to be in Octave? The object.method() calling convention is much more intuitive and more readable than method(object) IMHO. Also, it clearly allows to avoid name conflicts if I got some global function or another method with the same name...

Thanks,
joanna.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]