public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Zhang Wei Feng <weifeng.zhang@alcatel.be>
To: sidster <patrick@mail.boxsoft.com>
Cc: "gcc@gcc.gnu.org" <gcc@gcc.gnu.org>
Subject: Re: ambiguous overload ?
Date: Wed, 05 Jul 2000 03:27:00 -0000	[thread overview]
Message-ID: <39630D78.E9E018F6@alcatel.be> (raw)
In-Reply-To: <20000705025155.D3936@3eye.boxsoft.com>

Hi, patrick

Thanks for your inputs!

I have the following example working, though the difference is quite subtle!


#include <iostream>

using namespace std;

class Overload {
    int values[100];

public:
    // return coefficient reference for use as lvalue
    int& operator [](const int n) {
        return values[n];
    };

    // return coefficient for use as rvalue
    int operator [](const int n) const {
// NOTE without const, the compiler gets ambiguous error!
        return values[n];
    };

};


int main() {
    Overload over;

    for(int i = 0; i < 10 ; i++)
        over[i] = i;

    for(int i = 0; i < 10; i++)
        cout << "over[" << i << "] is " << over[i] << endl;

}

So as I noted above that if you forget the "const" for the rvalue operator,
then compiler still reports error. However, this do change the signature
of the function, but my question is

"Is that really difficult for normal functions( non-member functions) to differentiate
them by applying something like "const" " ?

Just for curiosity ;-)

weifeng




  reply	other threads:[~2000-07-05  3:27 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-07-05  2:19 Zhang Wei Feng
2000-07-05  2:52 ` sidster
2000-07-05  3:27   ` Zhang Wei Feng [this message]
2000-07-05  6:54     ` Neil Booth
2000-07-05 13:48       ` Martin v. Loewis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=39630D78.E9E018F6@alcatel.be \
    --to=weifeng.zhang@alcatel.be \
    --cc=gcc@gcc.gnu.org \
    --cc=patrick@mail.boxsoft.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).