Topic: (a + b).c() ?
Author: David Byrden <100101.2547@CompuServe.COM>
Date: 1995/04/21 Raw View
Scott;
Both of these should work fine in any compiler;
d().e (a+b).c()
with the proviso that, if the return type of d()
and operator+() is a class, rather than a reference,
(which it normally should be), then the object
you are working on is a temporary object which
will only survive for the duration of that entire
expression (including the function call c() )
There might be some cases in which d() would return
a reference to a permanent object elswhere.
In any case, the code is valid.
David Byrden
Author: kanze@us-es.sel.de (James Kanze US/ESC 60/3/141 #40763)
Date: 1995/04/19 Raw View
In article <34f7.smail.smayo@iii.net> smayo@iii1.iii.net (Scott Mayo)
writes:
|> Given a, an instance of some class A,
|> b, an instance of some class B,
|> +, an operator that works on A and B and
|> returns an instance of a class C, and
|> c(), some member function of class C,
|> is:
|> (a + b).c()
|> likely to be supported in all friendly implementations of C++?
Yes. The expression (a+b) creates a (temporary) C object, on which
member functions can be called.
|> I wouldn't question it for a moment, but in the nearest ANSI C
|> analogy, d().e, the dot operator is not quite defined (last I
|> checked) given that the left operand isn't being specific about
|> where the struct actually is.
I'm not sure, but I beleive that d().e *is* well defined in ANSI C, as
long as the function d() returns a struct (and not a pointer to a
struct) which contains an e.
Why do you say it is not defined?
--
James Kanze Tel.: (+33) 88 14 49 00 email: kanze@gabi-soft.fr
GABI Software, Sarl., 8 rue des Francs-Bourgeois, F-67000 Strasbourg, France
Conseils en informatique industrielle --
-- Beratung in industrieller Datenverarbeitung
Author: smayo@iii1.iii.net (Scott Mayo)
Date: 1995/04/18 Raw View
Given a, an instance of some class A,
b, an instance of some class B,
+, an operator that works on A and B and
returns an instance of a class C, and
c(), some member function of class C,
is:
(a + b).c()
likely to be supported in all friendly implementations of C++?
I wouldn't question it for a moment, but in the nearest ANSI C
analogy, d().e, the dot operator is not quite defined (last I
checked) given that the left operand isn't being specific about
where the struct actually is. Comments? The compiler I currently
use seems to accept it without a qualm, but then if I remember
it is one of the ones that tolerates d().e in its C flavor as well,
and I don't want a surprise when I switch to the competitor's brand.
Thanks.
--