Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C - C++ Learning > "const" keyword
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 10 Topic 4276 of 4370
Post > Topic >>

"const" keyword

by Ravi <Raul.Fremont@[EMAIL PROTECTED] > Sep 15, 2008 at 05:46 PM

I am not sure of the purpose of "const" keyword in the line:
int GetAge() const { return itsAge; }

If I remove the "const" keyword, the program still works.

class Mammal
 {
 public:
 // constructors
 Mammal();
 Mammal(int age);
 ~Mammal();

 //accessors
 int GetAge() const { return itsAge; }
 void SetAge(int age) { itsAge = age; }
 int GetWeight() const { return itsWeight; }
 void SetWeight(int weight) { itsWeight = weight; }


 protected:
 int itsAge;
 int itsWeight;
 }
 




 10 Posts in Topic:
"const" keyword
Ravi <Raul.Fremont@[EM  2008-09-15 17:46:08 
Re: "const" keyword
"Mike Wahler" &  2008-09-15 18:48:52 
Re: "const" keyword
Ben Bacarisse <ben.use  2008-09-16 02:57:43 
Re: "const" keyword
Ravi <Raul.Fremont@[EM  2008-09-16 16:39:52 
Re: "const" keyword
Richard Heathfield <rj  2008-09-17 03:14:01 
Re: "const" keyword
Ian Collins <ian-news@  2008-09-17 15:18:31 
Re: "const" keyword
"Mike Wahler" &  2008-09-17 06:36:21 
Re: "const" keyword
Francis Glassborow <fr  2008-09-21 23:23:54 
Re: "const" keyword
Ravi <Raul.Fremont@[EM  2008-10-06 19:35:53 
Re: "const" keyword
Francis Glassborow <fr  2008-10-07 09:07:37 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Nov 21 9:58:23 CST 2008.