home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / lang / cplus / 18403 < prev    next >
Encoding:
Text File  |  1992-12-24  |  1012 b   |  28 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!microsoft!hexnut!jimad
  3. From: jimad@microsoft.com (Jim Adcock)
  4. Subject: Re: Automatic conversion! Can we do this?
  5. Message-ID: <1992Dec24.185906.23522@microsoft.com>
  6. Date: 24 Dec 92 18:59:06 GMT
  7. Organization: Microsoft Corporation
  8. References: <1h7sq8INNr7e@function.mps.ohio-state.edu>
  9. Lines: 17
  10.  
  11. In article <1h7sq8INNr7e@function.mps.ohio-state.edu> ren@function.mps.ohio-state.edu (Liming Ren) writes:
  12. |string a, b("Merry");
  13. |a=b+" Chrismas";
  14. |a="C" + b;
  15. |
  16. |But I can't do:   a="Merry" + " Chrismas";
  17. |The compiler complains that "pointer +pointer" and the conversion does not 
  18. |happen. I tried to overload + with (char*, char*). The compiler did not 
  19. |allow me. 
  20.  
  21. The language does not allow you to do this.  Overloaded operators must
  22. take at least one parm of class type.  (ptr + ptr) is defined to be an error
  23. by the language and you cannot overload this behavior because of the previous
  24. rule.  The closest you can come is:
  25.  
  26.     a = (string) "Merry" + " Christmas";
  27.  
  28.