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

7 ビュー (過去 30 日間)
Tuncay Eren
Tuncay Eren 2017 年 6 月 23 日
コメント済み: Tuncay Eren 2017 年 6 月 23 日
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 Center および File ExchangeMethods についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by