Effacer les filtres
Effacer les filtres

Defining Private and Public Fields within a Struct

9 vues (au cours des 30 derniers jours)
Courtney
Courtney le 15 Juin 2023
Modifié(e) : Courtney le 16 Juin 2023
I see that in cpp you can define a struct to have private and public members. However, I do not see that option within Matlab. I know that there is option to use classes, however I would like to understand better if structs can have this as well.
  2 commentaires
Walter Roberson
Walter Roberson le 16 Juin 2023
I see that in cpp you can define a struct to have private and public members.
C++ standard section reference, please.
I believe you are mistaken. I think you are talking about C++ classes, not C++ struct .
Courtney
Courtney le 16 Juin 2023
Modifié(e) : Courtney le 16 Juin 2023
Hi @Walter Roberson there are many articles online that show examples of C++ structs being able to define private members, as public members are default. Thank you for your swift feedback! It sounds like from other comments as well that this is not possible in Matlab.

Connectez-vous pour commenter.

Réponse acceptée

Steven Lord
Steven Lord le 16 Juin 2023
No, all fields in a struct are publicly accessible.

Plus de réponses (1)

lazymatlab
lazymatlab le 16 Juin 2023
Modifié(e) : lazymatlab le 16 Juin 2023
As far as I know, matlab struct does not support access modifiers. Maybe you need to write a class which starts like this:
classdef myClass < handle
properties (Access = public)
public1
public2
end
properties (Access = private)
private1
private2
end
For more information: Property Attributes

Catégories

En savoir plus sur Structures 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