What is the meaning of empty parenthesis in Matlab Object Oriented Programming?

3 vues (au cours des 30 derniers jours)
I have been working on OFDM using Object Oriented methadology and in the following code block trying to understand the usage of the functions with empty parenthesis.
In the code the first function with obj in the paranthesis but the others have empty paranthesis. Could you please help how to interpret the empty ones?
classdef OFDM_Signal
properties
...
end
methods
function obj=OFDM_Signal(StructParameters)
....
end
end
methods
function ofdmTransmitter(Obj)
% Source
Obj.genOfdmBits();
% TxBits to symbol conversion (mapper)
Obj.getOfdmData();
......
end
end
end

Réponse acceptée

Guillaume
Guillaume le 23 Juin 2017
It's the same meaning as for normal functions: it does not mean anything. It's calling the function or method with no arguments and the parenthesis could be omitted.
The only reason for writing the parenthesis is to convey to the reader that you're calling a method of the class instead of accessing a property of the class. I.e. I would write:
a = obj.someproperty;
b = obj.somefuncwithnoargs();
to make clear that someprop is a property and somefuncwithnoargs is a function. It's just a matter of preference. As said the parenthesis are optional.
This may also be a hang up from other languages such as C++, where parenthesis are always required for function calls.

Plus de réponses (0)

Catégories

En savoir plus sur Construct and Work with Object Arrays dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by