D
Der Andere
What exactly is the sense of using a "const" modifier before a function
declaration? Actually, you can use it in three places. For instance, take a
look at the following function declaration (from the introductory book
"Absolute C++" by W. Savitch, p. 315)
class Money
{
Money();
const Money operator + (const Money& amount2) const;
private:
int dollars;
int cents;
}
I didn't copy the whole code (there are many more member functions), but
this should suffice for the question.
The meaning of the "const" before the parameter "amount2" is obvious to me;
the "const" just before the semicolon signals that the function may not
change the calling object if I got it right. But what about the first
"const"?
Cheers,
Matthias
declaration? Actually, you can use it in three places. For instance, take a
look at the following function declaration (from the introductory book
"Absolute C++" by W. Savitch, p. 315)
class Money
{
Money();
const Money operator + (const Money& amount2) const;
private:
int dollars;
int cents;
}
I didn't copy the whole code (there are many more member functions), but
this should suffice for the question.
The meaning of the "const" before the parameter "amount2" is obvious to me;
the "const" just before the semicolon signals that the function may not
change the calling object if I got it right. But what about the first
"const"?
Cheers,
Matthias