By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,905 Members | 1,283 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,905 IT Pros & Developers. It's quick & easy.

using const keyword

P: 1
Hello Guys!!

Could you please tell me what is the difference in giving "const" keyword either before or after the function

eg: const int f();
int f() const;
const int f() const: // what happens in this case

(I guess it doesn't matter wherever we declare "const" keyword)

Waiting for your replies

Thanking you all
Jun 1 '07 #1
Share this Question
Share on Google+
1 Reply


Banfa
Expert Mod 5K+
P: 8,916
Are you talking about inside a class (or stucture) definition?

I believe const after a function is only valid for a member function of a class (or structure) in this case it means that the function does not alter any of the data members of the class (or stucture) with the exception of members declared as mutable.

The const keyword before any function is a modifer of it's return type, the example you give is poor because you can not modifiy the return value of a function that returns a basci type but if the function returned a pointer then declaring it const would mean that it return a pointer to data that was not modifiable.
Jun 1 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.