-
April 22nd, 2011, 04:49 PM
#1
reference
What can i say about these two's differences ?
reference opeartor[](size s);
const_reference opeartor[](size s);
Thank you.
-
April 22nd, 2011, 10:03 PM
#2
Re: reference
One returns a reference, the other returns a const_reference
Actually, these are probably member functions, and the one that returns a const_reference probably should be declared const. Also, it is operator, not opeartor.
-
April 23rd, 2011, 01:30 AM
#3
Re: reference
Thank you, i copied and pasted without rereading them. Now I fix them,
reference operator[](size_type s);
const_reference operator[](size_type s);
I guess I made a wrong question, mine should have been
int & func( int arg);
const int & func(int arg);
This simple! But i can only imagine that the return types between both are different, and it's vague to me that the const-ness in the latter is seemingly redundant (as for what sake one needs to change the returned value that is...already returned)
??????????
-
April 23rd, 2011, 01:53 AM
#4
Re: reference
Originally Posted by Lucassergei
But i can only imagine that the return types between both are different, and it's vague to me that the const-ness in the latter is seemingly redundant (as for what sake one needs to change the returned value that is...already returned)
So that you can write stuff such as:
or in the case of operator[],
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|