home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / cplus / 13144 < prev    next >
Encoding:
Internet Message Format  |  1992-09-01  |  1.7 KB

  1. Path: sparky!uunet!igor!thor!rmartin
  2. From: rmartin@thor.Rational.COM (Bob Martin)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Destruction of temporaries
  5. Message-ID: <rmartin.715356168@thor>
  6. Date: 1 Sep 92 14:02:48 GMT
  7. References: <rmartin.715004480@thor> <23583@alice.att.com> <rmartin.715101472@thor> <1992Aug31.162915.2577@Warren.MENTORG.COM>
  8. Sender: news@Rational.COM
  9. Lines: 41
  10.  
  11. adk@Warren.MENTORG.COM (Ajay Kamdar) writes:
  12.  
  13. |In article <rmartin.715101472@thor> rmartin@thor.Rational.COM (Bob Martin) writes:
  14. |>
  15. |>No, I want a warning every time a temporary gets converted into a
  16. |>pointer.  
  17. |>
  18. |>In your example:  Given String::operator char*(); 
  19. |>                    and String String::operator+(const String&);  : 
  20. |>
  21. |>String a,b;
  22. |>char* c = a+b;
  23. |>
  24. |>An implicit conversion to char* takes place on a temporary.  A warning
  25. |>should be possible.  
  26. |>
  27.  
  28. |But what if operator char* () is coded as follows:
  29.  
  30. |String::operator char*()
  31. |{
  32. |    char *ncptr = new char[strlen(d_cptr) + 1];
  33. |      // d_cptr is the data member pointing to String's char* representation
  34. |    strcpy(ncptr, d_cptr);
  35. |    return ncptr;
  36. |      // reclamation of newed memory is somehow taken care of
  37. |}
  38.  
  39. |I wouldn't want the compiler to issue warnings in such a case, irrespective
  40. |of whether operator char*() was called on a temporary or not.
  41.  
  42. Then, you should cajole your compiler vender into supplying you with a
  43. compiler which provides you with the type of #pragma control that lets
  44. you supress the warnings on a function by function basis.
  45.  
  46.  
  47. --
  48. Robert Martin                        Training courses offered in:
  49. R. C. M. Consulting                       Object Oriented Analysis
  50. 2080 Cranbrook Rd.                        Object Oriented Design
  51. Green Oaks, Il 60048 (708) 918-1004       C++
  52.