home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / cplus / 18015 < prev    next >
Encoding:
Text File  |  1992-12-15  |  1.8 KB  |  71 lines

  1. Path: sparky!uunet!olivea!spool.mu.edu!umn.edu!csus.edu!netcom.com!netcomsv!delfin.com!delfin.com!mr
  2. From: mr@delfin.com (Mark Rosenberg)
  3. Newsgroups: comp.lang.c++
  4. Subject: What is this CFRONT 3.0 warning message trying to tell me?
  5. Message-ID: <1992Dec15.183649.20994@delfin.com>
  6. Date: 15 Dec 92 18:36:49 GMT
  7. Sender: mr@yang (Mark Rosenberg)
  8. Reply-To: mark@delfin.com
  9. Organization: Delfin Systems, Sunnyvale CA
  10. Lines: 58
  11. Nntp-Posting-Host: merlin
  12.  
  13. I'm porting a large application from a CFRONT 2.1-based compiler (Sun) to
  14. a CFRONT 3.0-based compiler (Solbourne). The following warning message
  15. has me somewhat mystified:
  16.  
  17. "main.cc", line 31: warning: temporary used for non-const Thing& argument; no changes will be propagated to actual argument (anachronism)
  18.  
  19. I've boiled the offending code down to:
  20.  
  21. #include <string.h>
  22. #include <malloc.h>
  23. #include <stdio.h>
  24. class Thing
  25. {
  26.    public:
  27.  
  28.    char *str;
  29.    Thing(){ str = (char *)0; };
  30.    Thing(char *s){str=strdup(s);};
  31.    Thing &operator = ( Thing & rhs  );
  32. };
  33.  
  34. Thing &
  35. Thing::operator = ( Thing & rhs )
  36. {
  37.    if( this->str )free( this->str );
  38.    strcpy( this->str, rhs.str );
  39.    return *this;
  40. }
  41.  
  42. Thing getThing()
  43. {
  44.    Thing t("a thing");
  45.    return t;
  46. }
  47.  
  48. main()
  49. {
  50.    Thing t1("");
  51.    t1 = getThing();             // warning
  52.    printf("value: %s\n", t1.str );
  53.  
  54.    Thing t2 = getThing();       // no warning
  55.    printf("value: %s\n", t2.str );
  56. }
  57.  
  58. When this program is run you get the expectable result:
  59.  
  60. value: a thing
  61. value: a thing
  62.  
  63. I realize that getThing should really return a reference and that using
  64. stdio is really bad style but I don't understand why the first call to
  65. getThing generates a warning but the second doesn't.
  66. -- 
  67. Mark Rosenberg
  68. internet:mark@delfin.com
  69. phone: (408) 562-1126    fax: (408) 748-1140
  70. snail: Delfin Systems, 3000 Patrick Henry Drive, Santa Clara, CA 95054-1814
  71.