Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

virtual char *functionName (arguments...) const;

Status
Not open for further replies.

Benjamin

Programmer
Jan 12, 2000
10
US
Hi,<br>
<br>
I'm a bit rusty at remembering what I study in college. Can anyone tell me<br>
what is the const; at the end of the function actually does?<br>
<br>
class someName {<br>
<br>
public:<br>
...<br>
protected:<br>
virtual char *functionName (args...) const; &lt;--- what does const mean?<br>
private:<br>
...<br>
<br>
Thank you,<br>
Ben
 
A friend of mine found a book with the description of the const above. The<br>
description goes:<br>
<br>
Found in book: C++ How to Program (2nd Edition) by Deitel & Deitel<br>
<br>
C++ compilers disallow any member function calls for const objects unless the member functions themselves are also declared const. This is true even for get member functions that do not modify the object. Member functions declared const cannot modify the object -- the compiler disallows this.<br>
<br>
A function is specified as const both in its prototype and in its definition by inserting the keyword const after the function's parameter list, and, in the case of the function definition, before the left brace that begins the function body. For example, the following member function of class A<br>
<br>
int A::getValue() const { return privateDatamember };<br>
<br>
simply returns the value of one of the object's data members, and is appropriately declared const.<br>
<br>
Thanks to anyone who tried to help.<br>
Ben
 
The const at the end of a function means : This function is not going to change any member variables of that class. Suppose you have a class of variables and member functions. And if you want a particular member function to print values of member variables only. You can declare that function with const suffix. <br>
<br>
Does this answer your question ?<br>
Thanx<br>
Siddhartha Singh<br>
<A HREF="mailto:ssingh@aztecsoft.com">ssingh@aztecsoft.com</A>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top