Home Forums C Programming NEED HELP URGENTLY !!!!

Viewing 2 reply threads
  • Author
    Posts
    • #2106
      Anantha
      Participant

      hi to whoever reading this. I’m a complete noob to c++ so bare with me if it’s a simple question.
      So, here goes my question:

      What does the question mean by: implementing getter with const method?? Can anyone of you give me an example to this question??

      Thanks

    • #3399
      Humayan
      Participant

      Do you mean a constant method of a class implementation? A constant member function of a class is a function that does not alter any class data members , like:
       
       

      class X
      {
      public:
      int age() const { return mAge; } //const get method
      void age(int age) { mAge = age; } //( accessor! )
      private:
      int mAge;
      };

       check out this link: http://www.uwyn.com/resources/uwyn_cpp_coding_standard/x496.html

    • #3400
      Anantha
      Participant

      Thanks cman! Actually i was kinda confuse on where to put the “const”
      For example:

      const int getName();
      int getName() const;

      what’s the difference between putting the “const” in front and at the back?
       

Viewing 2 reply threads
  • The forum ‘C Programming’ is closed to new topics and replies.