🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #162

Re: Answers on a postcard

#162
From: Markku Sakkinen
Date: Mon, 14 Sep 1992 08:34
41 lines
2012 bytes
In article <BuH6sK.54r@world.std.com> tob@world.std.com (Tom O Breton) writes:
>Karl:
>
>> If not, I would ask: How does one overload the comma operator while
>> maintaining its attibutes as an operator?
>
>
>It's of dubious usefulness but it can be done:
>
>class thisclass
>{ int&  operator,(int a); }
>
>//To call this:  (thisclass)X, (int)Y ... (outside of arg-lists, of course)
>  
>This will return you an int, just as if the default comma operator had
>executed.
> ...

Sorry, but you did not see what the problem is.
With an overloaded comma operator it is impossible to make sure
that the first operand (X) is _evaluated_ (completely) before
the second one, as is the case with the built-in operator.
Indeed, one would probably often like not to have the second operator
evaluated yet at all before the operator function is invoked.
This is important if either of the operands is an expression
with side effects (and with the built-in comma, you would not use
it at all unless the first operand really has side effects).

BTW, I regard it as a mistake to make comma (and '&') overloadable at all.
It is a clear breach of the principle: "C++ was designed to be
extensible, but not mutable".

----------------------------------------------------------------------
Markku Sakkinen (sakkinen@jytko.jyu.fi)
       SAKKINEN@FINJYU.bitnet (alternative network address)
Department of Computer Science and Information Systems
University of Jyvaskyla (a's with umlauts)
PL 35
SF-40351 Jyvaskyla (umlauts again)
Finland
----------------------------------------------------------------------
Technical Details
Message-ID: <1992Sep14.083425.2938@jyu.fi>
Path: arc1-ca.pugleaf.net!sparky!uunet!mcsun!news.funet.fi!network.jyu.fi!sakkinen
References: <92255.154216KKEYTE@ESOC.BITNET> <BuH6sK.54r@world.std.com>

Show Full Headers
Complete Article Headers
Newsgroups: comp.std.c++
Path: arc1-ca.pugleaf.net!sparky!uunet!mcsun!news.funet.fi!network.jyu.fi!sakkinen
From: sakkinen@jyu.fi (Markku Sakkinen)
Subject: Re: Answers on a postcard
Message-ID: <1992Sep14.083425.2938@jyu.fi>
Organization: University of Jyvaskyla, Finland
References: <92255.154216KKEYTE@ESOC.BITNET> <BuH6sK.54r@world.std.com>
Date: Mon, 14 Sep 1992 08:34:25 GMT
Lines: 41