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

What's wrong Overloading []

P: n/a
Hello
My gcc copiler write this
TypEle& Tablica<TypEle>::operator[](unsigned int) [with TypEle = int]
' and `
TypEle Tablica<TypEle>::operator[](unsigned int) [with TypEle = int]'
cannot be overloaded

where TypEle is tempalte type, Tablica is table object.

TypEle Tablica<TypEle>::operator[](unsigned int) [with TypEle = int]
I use for Tablica<int> tab1; int X;
X = tab1[23] and this work great but when I added
TypEle& Tablica<TypEle>::operator[](unsigned int) [with TypEle = int]
for tab[1] = X it doen't work. With second operator i can't compile. How
should i corect this ??
Jul 22 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
SinusX wrote:
My gcc copiler write this
TypEle& Tablica<TypEle>::operator[](unsigned int) [with TypEle = int]
' and `
TypEle Tablica<TypEle>::operator[](unsigned int) [with TypEle = int]'
cannot be overloaded

where TypEle is tempalte type, Tablica is table object.

TypEle Tablica<TypEle>::operator[](unsigned int) [with TypEle = int]
I use for Tablica<int> tab1; int X;
X = tab1[23] and this work great but when I added
TypEle& Tablica<TypEle>::operator[](unsigned int) [with TypEle = int]
for tab[1] = X it doen't work. With second operator i can't compile. How
should i corect this ??


The compiler complains because the difference between the two functions is
only in the return value type. You probably mean to make the second one
'const':

TypEle Tablica<TypEle>::operator[](unsigned int) const;

while leaving the first one as is:

TypEle& Tablica<TypEle>::operator[](unsigned int);

See the difference? The one that returns a reference should not be const,
most likely.

Victor
Jul 22 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.