How access object properties from internal functions

Hi
My system : Windows 10 (version 2004)** or Ubuntu 20.04

  • Octave version: 6.2.0
  • Installation method: Downloaded and installed “octave-6.1.0-w64-installer.exe” from https://www.octave.org/download.html
    I am a novice on Octave and I apologize for the question (I am not be able to find an answer):
    I would create a class with a static method that can be called directly or by an object instance.
    Below a nutshell sample:
classdef obj
	properties
		X = 70;
	end
	methods
		function p = obj (a)
		end
	end
	methods (Static = true)
		function p = fGen (a)        
			X
                        a
		end
	end
end

here what happens:

>> o = obj;
...
>> o.fGen("Try")
error: 'X' undefined near line 11, column 11
...
>> obj.fGen("Try")
error: 'X' undefined near line 11, column 11
...

thanks

Static functions can be called without an instance of the respective object. So you can’t access its properties (because they aren’t initialized).
If the function needs access to the object properties, it can’t be static.

Thanks mmuetzel
this clarifie a little, but even with the instantiated object I don’t know how to access its properties and methods (maybe this or self …?) see below.

>> obj.fGen("Try")
error: 'X' undefined near line 11, column 11

Excuse me, this is correct sample.

See the manual:
Methods (GNU Octave (version 6.2.0))

In general, the first argument in a method definition is always the object that it is called from.

E.g.:

classdef obj
  properties
    X = 70;
  end
  methods
    function p = obj (a)
    end

    function p = fGen (this, a)        
      this.X
      a
    end
  end
end

Also, ordinary methods may be called with either obj.method (args) or method (obj, args) and public properties are accessible with the syntax obj.propname or obj.('propname') just as you would access struct fields.

The name of the first argument for a method is not required to be this or obj but those are commonly used.

Thanks jwe and mmuetzel
I understood how it works when I instantiated the object; what I don’t know is how to access a method from a static method (I also understood that properties only exist with instantiation)

I take advantage of your availability to submit another related question:
I have a class that generate a GUI, but I have troubles when dealing with CallBack functions.

...
        buttons.fg_Ok = {@fg_exit ["Ok"]};  % this describe a button
...
% here i (de)generate a button whith caption and callback function        
btn = uicontrol ("parent", p, "string",buttons.(char(fn(k)))(2), "position", [startBtn yPos buttonsDim 0.8*deltaY]);
        set(btn,"CallBack", buttons.(char(fn(k)))(1))
--
function fg_exit(src)
  ...
end

fg_exit function is both external to the class both like a method of class; when I execute the script and click on the “Ok” button I receive:

error: feval: function ‘fg_exit’ not found

thaks in advance