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

2 次查看(过去 30 天)
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

采纳的回答

Guillaume
Guillaume 2017-6-23
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Construct and Work with Object Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by