Path: utzoo!mnetor!tmsoft!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!uunet!microsoft!jimad From: jimad@microsoft.UUCP (Jim ADCOCK) Newsgroups: comp.lang.c++ Subject: Re: How many arguments for operator() and operator[]? Keywords: overloading, operator, arguments Message-ID: <70485@microsoft.UUCP> Date: 5 Feb 91 19:18:32 GMT References: <19587@shlump.nac.dec.com> Reply-To: jimad@microsoft.UUCP (Jim ADCOCK) Organization: Microsoft Corp., Redmond WA Lines: 32 In article <19587@shlump.nac.dec.com> heintze.fmcsse.enet.dec.com (Sieg Heintze) writes: >Could someone point me to the place in the Stroustrup and Ellis C++ Reference >manual where they define the number of arguments permitted when defining >a member function that overloads operator() or operator[]. > >I have tried this program on three compilers and all three behave differently. >I'm wondering how other C++ compilers behave and just what the correct >behavour is. See ARM page 335-337. Overloaded operators are suppose to follow the same syntax as built-in operators. Thus, op[] can only have two operators -- foo[bar] has a first [implied] parameter of foo, and a second parameter of bar. Op[] must be a non-static member function. The usage form of op() is: primary-expression(optional-expression-list) op() must also be a non-static member function. Thus: int X::operator()(); foo X::operator()(int x, double y); foo X::operator()(int x); double X::operator()(int a, int b, int c, int d, int f, double x); should all be accepted. ARM refers to op() as being a "binary operator" -- which might have confused some implementors -- though ARM does give examples of op() being used with totals of three and four parameters.