What is the difference between accessor and mutator methods?

后端 未结 2 1983
名媛妹妹
名媛妹妹 2020-12-14 10:43

How are accessors and mutators different? An example and explanation would be great.

2条回答
  •  余生分开走
    2020-12-14 11:33

    class foo
    {
        private:
    
            int a;
        public:
            int  accessA() const { return(a);}
            void mutateA(const int A) { a = A;}
    }
    

    Also known as getters and setters and probably a dozen other terms.

提交回复
热议问题