home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!portal!cup.portal.com!Aurelius
- From: Aurelius@cup.portal.com (Mark Christian Barnes)
- Newsgroups: comp.lang.c++
- Subject: Re: complex classes and temporary destruction.
- Message-ID: <64992@cup.portal.com>
- Date: Mon, 31 Aug 92 00:09:30 PDT
- Organization: The Portal System (TM)
- Distribution: world
- References: <MCGRANT.92Aug26232410@rascals.stanford.edu>
- <23563@alice.att.com> <64821@cup.portal.com> <23578@alice.att.com>
- <64878@cup.portal.com> <23587@alice.att.com> <64915@cup.portal.com>
- <23592@alice.att.com>
- Lines: 45
-
- Andrew Koenig replies:
-
- |> If operator+(a,b) does, in fact, construct a temporary of type
- |> String, then the compiler could determine its storage class,
- |> perhaps based upon the storage class of the context to which
- |> it is applied.
- |
- |Sorry, but I'm not going to tell you what operator+(a,b) does.
- |I'm compiling it separately and giving you the object code to link
- |in with your source code.
- |
- |Now, how is the compiler going to determine its storage class when
- |it is compiling your program?
-
- Hmm, ok. Well then I'll write code defensively like:
-
- extern class String;
- extern String a, b;
-
- void display ( void )
- {
- auto String temp;
- auto char const *p;
- auto char const statement[] = "a+b is ";
- auto char const endOfLine[] = ".\n";
-
- temp = a + b; // invoke String operator+()
- p = temp; // invoke String operator char const *()
- cout << statement << p << endOfLine;
-
- // every variable gets destructed about now. (except cout, a and b)
- }
-
- In every case (well, so far ;-}) an unnamed object can be
- declared as a variable with a known storage class. This is
- why I feel that such "temporary" objects could be treated as
- responsibly by a smart compiler. The kind of compiler C++
- has been striving towards.
-
- I, as the programmer, can (and usually must) make such
- determinations. I sometimes eliminate all unnamed objects during
- alpha testing, in order to judge how well I've used the machine's
- resources, within my functions and methods.
-
- Regards, Aurelius@cup.portal.com
-