中易网

c++里 accessor 和 mutator 分别指什么?

答案:2  悬赏:80  
解决时间 2021-02-08 02:39
c++里 accessor 和 mutator 分别指什么?
最佳答案
都指一样的东西。
让某个变量只能通过公共方法来存取,这些变量就叫accessor或mutator。
比如
学生类中的有姓名变量name
我只设name为私有private,只能通过公共方法getName()和setName(n)存取。
这样在外部就根本不知道name在哪里存储,甚至name变量本身都可以不存在,对外只需要知道"Name"这个名称,就能操作这个想象中的Name变量。
此时'name'这个名称就成了一种accessor存取器或叫mutator变值器。
全部回答
简单的说就是我们常见的bean中的get/set方法。mutator methods是set方法,accessor methods是get方法。 public class requestparameters { private string id; // accessor method public final string getid() { return id; } // mutator method public final void setid(string id) { this.id =id; } } an accessor method is used to return the value of a private field. it follows a naming scheme prefixing the word "get" to the start of the method name. these methods always return the same data type as their corresponding private field (e.g., string) and then simply return the value of that private field. a mutator method is used to set a value of a private field. it follows a naming scheme prefixing the word "set" to the start of the method name. these methods do not have a return type and accept a parameter that is the same data type as their corresponding private field. the parameter is then used to set the value of that private field.
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
杉山子在什么地方啊,我要过去处理事情
广东有哪些大学
家里给找的高铁乘务员的工作。说是培训费所有
<三国传高达模型>:吕布天玉铠是否=玄武装
婉斌或婷斌的谐音四字词语
怎样分解数学应用题
狗狗配种8天吐黄色分泌物?
鄂托克旗城市房屋拆迁管理办公室怎么去啊,有
无花果迁插长叶后不久叶子又委迷掉叶死了怎么
苹果5s64g全网的价格多少
1,15,23,36,41,57,63,79,87,96,12
班上一个女生在她旁边没人的时候,总爱叫我做
未婚先孕登记结婚和妇女主任有关系吗?
壹公馆娱乐会所在哪里啊,我有事要去这个地方
有谁知道济南市的卖狗的宠物市场在哪,要怎么
推荐资讯
断路器s253s-c20啥意思
窍开头的成语,,急用...
告白词...
nike红喷最小码是多少啊。
我的电脑这几天不知道怎么开不了机了。。
歌词是you will win and i will die什么的,
指名是什么意思及读法
原汁原味木桶饭(德安店)地址在什么地方,想过
赵丽颖发展趋势真的下滑了吗?
中国移动银河特约代理点怎么去啊,有知道地址
吉林2012下半年的实习律师培训是什么时候开始
我是大专学历,机械设计专业的,但平时喜欢做
手机登qq时,显示手机磁盘不足,清理后重新登
刺客的套装怎么选啊?