home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!news.mentorg.com!sdl!adk
- From: adk@Warren.MENTORG.COM (Ajay Kamdar)
- Subject: Re: Destruction of temporaries
- Message-ID: <1992Aug31.162915.2577@Warren.MENTORG.COM>
- Organization: Mentor Graphics Corp. - IC Group
- References: <rmartin.715004480@thor> <23583@alice.att.com> <rmartin.715101472@thor>
- Date: Mon, 31 Aug 1992 16:29:15 GMT
- Lines: 43
-
- In article <rmartin.715101472@thor> rmartin@thor.Rational.COM (Bob Martin) writes:
- >ark@alice.att.com (Andrew Koenig) writes:
- >|
- >|Which cases? I don't know how to write a compiler smart enough to
- >|distinguish the innocent cases from the guilty ones. Surely you're
- >|not suggesting a warning every time you call a function that returns
- >|a pointer!
- >|--
- >
- >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.
-
- - Ajay
-
- --
- I speak for none but myself.
-
- Ajay Kamdar Email : ajay_kamdar@mentorg.com
- Mentor Graphics, IC Group (Warren, NJ) Phone : (908) 580-0102
-