What's wrong Overloading []

S

SinusX

Hello
My gcc copiler write this
TypEle& Tablica<TypEle>::eek:perator[](unsigned int) [with TypEle = int]
' and `
TypEle Tablica<TypEle>::eek:perator[](unsigned int) [with TypEle = int]'
cannot be overloaded

where TypEle is tempalte type, Tablica is table object.

TypEle Tablica<TypEle>::eek:perator[](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>::eek:perator[](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 ??
 
V

Victor Bazarov

SinusX said:
My gcc copiler write this
TypEle& Tablica<TypEle>::eek:perator[](unsigned int) [with TypEle = int]
' and `
TypEle Tablica<TypEle>::eek:perator[](unsigned int) [with TypEle = int]'
cannot be overloaded

where TypEle is tempalte type, Tablica is table object.

TypEle Tablica<TypEle>::eek:perator[](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>::eek:perator[](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>::eek:perator[](unsigned int) const;

while leaving the first one as is:

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

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

Victor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,169
Messages
2,570,919
Members
47,460
Latest member
eibafima

Latest Threads

Top