home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / cplus / 13096 < prev    next >
Encoding:
Text File  |  1992-08-31  |  1.7 KB  |  54 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!news.mentorg.com!sdl!adk
  3. From: adk@Warren.MENTORG.COM (Ajay Kamdar)
  4. Subject: Re: Destruction of temporaries
  5. Message-ID: <1992Aug31.162915.2577@Warren.MENTORG.COM>
  6. Organization: Mentor Graphics Corp. - IC Group
  7. References: <rmartin.715004480@thor> <23583@alice.att.com> <rmartin.715101472@thor>
  8. Date: Mon, 31 Aug 1992 16:29:15 GMT
  9. Lines: 43
  10.  
  11. In article <rmartin.715101472@thor> rmartin@thor.Rational.COM (Bob Martin) writes:
  12. >ark@alice.att.com (Andrew Koenig) writes:
  13. >|
  14. >|Which cases?  I don't know how to write a compiler smart enough to
  15. >|distinguish the innocent cases from the guilty ones.  Surely you're
  16. >|not suggesting a warning every time you call a function that returns
  17. >|a pointer!
  18. >|-- 
  19. >
  20. >No, I want a warning every time a temporary gets converted into a
  21. >pointer.  
  22. >
  23. >In your example:  Given String::operator char*(); 
  24. >                    and String String::operator+(const String&);  : 
  25. >
  26. >String a,b;
  27. >char* c = a+b;
  28. >
  29. >An implicit conversion to char* takes place on a temporary.  A warning
  30. >should be possible.  
  31. >
  32.  
  33. But what if operator char* () is coded as follows:
  34.  
  35. String::operator char*()
  36. {
  37.     char *ncptr = new char[strlen(d_cptr) + 1];
  38.       // d_cptr is the data member pointing to String's char* representation
  39.     strcpy(ncptr, d_cptr);
  40.     return ncptr;
  41.       // reclamation of newed memory is somehow taken care of
  42. }
  43.  
  44. I wouldn't want the compiler to issue warnings in such a case, irrespective
  45. of whether operator char*() was called on a temporary or not.
  46.  
  47. - Ajay
  48.  
  49. -- 
  50. I speak for none but myself.
  51.  
  52. Ajay Kamdar                               Email : ajay_kamdar@mentorg.com
  53. Mentor Graphics, IC Group (Warren, NJ)    Phone : (908) 580-0102
  54.