home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!igor!thor!rmartin
- From: rmartin@thor.Rational.COM (Bob Martin)
- Newsgroups: comp.lang.c++
- Subject: Re: Destruction of temporaries
- Message-ID: <rmartin.715356168@thor>
- Date: 1 Sep 92 14:02:48 GMT
- References: <rmartin.715004480@thor> <23583@alice.att.com> <rmartin.715101472@thor> <1992Aug31.162915.2577@Warren.MENTORG.COM>
- Sender: news@Rational.COM
- Lines: 41
-
- adk@Warren.MENTORG.COM (Ajay Kamdar) writes:
-
- |In article <rmartin.715101472@thor> rmartin@thor.Rational.COM (Bob Martin) writes:
- |>
- |>No, I want a warning every time a temporary gets converted into a
- |>pointer.
- |>
- |>In your example: Given String::operator char*();
- |> and String String::operator+(const String&); :
- |>
- |>String a,b;
- |>char* c = a+b;
- |>
- |>An implicit conversion to char* takes place on a temporary. A warning
- |>should be possible.
- |>
-
- |But what if operator char* () is coded as follows:
-
- |String::operator char*()
- |{
- | char *ncptr = new char[strlen(d_cptr) + 1];
- | // d_cptr is the data member pointing to String's char* representation
- | strcpy(ncptr, d_cptr);
- | return ncptr;
- | // reclamation of newed memory is somehow taken care of
- |}
-
- |I wouldn't want the compiler to issue warnings in such a case, irrespective
- |of whether operator char*() was called on a temporary or not.
-
- Then, you should cajole your compiler vender into supplying you with a
- compiler which provides you with the type of #pragma control that lets
- you supress the warnings on a function by function basis.
-
-
- --
- Robert Martin Training courses offered in:
- R. C. M. Consulting Object Oriented Analysis
- 2080 Cranbrook Rd. Object Oriented Design
- Green Oaks, Il 60048 (708) 918-1004 C++
-