home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / lang / cplus / 16033 < prev    next >
Encoding:
Text File  |  1992-11-10  |  1.3 KB  |  41 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!newsgate.watson.ibm.com!yktnews!admin!siena!mittle
  3. From: mittle@watson.ibm.com (Josh Mittleman)
  4. Subject: Re: Constructor doesn't use overloading??
  5. Sender: news@watson.ibm.com (NNTP News Poster)
  6. Message-ID: <1992Nov10.165600.101353@watson.ibm.com>
  7. Date: Tue, 10 Nov 1992 16:56:00 GMT
  8. Disclaimer: This posting represents the poster's views, not necessarily those of IBM
  9. References:  <92315.1041030407658@QUCDN.QueensU.CA>
  10. Nntp-Posting-Host: siena.watson.ibm.com
  11. Organization: IBM T.J. Watson Research Center
  12. Lines: 27
  13.  
  14.  
  15. > My surprise is that in main(), if I have:
  16. >   void main()
  17. >   {    time t1(7, 5, 125) ;
  18. >        time t2(6,2) ;
  19. >        time t3 = t1 ;
  20. >        ...
  21. > the overloaded = is not called...
  22.  
  23. That is correct.  This statement is an initialization, not an assignment.
  24. C++ maintains a strict distinction between the two operations.
  25. Initializations invoke a constructor; assignments invoke an assignment
  26. operator.  The statement:
  27.  
  28.   time t3 = t1;
  29.  
  30. is equivalent to:
  31.  
  32.   time t3(t1);
  33.  
  34. and invokes the copy constructor.  See ARM, p.284, section 12.6, for
  35. details.
  36.  
  37. ===========================================================================
  38. Josh Mittleman (mittle@watson.ibm.com)
  39. J2-C28 T.J. Watson Research Center, PO Box 704, Yorktown Heights, NY  10598
  40.