home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!newsgate.watson.ibm.com!yktnews!admin!siena!mittle
- From: mittle@watson.ibm.com (Josh Mittleman)
- Subject: Re: Constructor doesn't use overloading??
- Sender: news@watson.ibm.com (NNTP News Poster)
- Message-ID: <1992Nov10.165600.101353@watson.ibm.com>
- Date: Tue, 10 Nov 1992 16:56:00 GMT
- Disclaimer: This posting represents the poster's views, not necessarily those of IBM
- References: <92315.1041030407658@QUCDN.QueensU.CA>
- Nntp-Posting-Host: siena.watson.ibm.com
- Organization: IBM T.J. Watson Research Center
- Lines: 27
-
-
- > My surprise is that in main(), if I have:
- >
- > void main()
- > { time t1(7, 5, 125) ;
- > time t2(6,2) ;
- > time t3 = t1 ;
- > ...
- > the overloaded = is not called...
-
- That is correct. This statement is an initialization, not an assignment.
- C++ maintains a strict distinction between the two operations.
- Initializations invoke a constructor; assignments invoke an assignment
- operator. The statement:
-
- time t3 = t1;
-
- is equivalent to:
-
- time t3(t1);
-
- and invokes the copy constructor. See ARM, p.284, section 12.6, for
- details.
-
- ===========================================================================
- Josh Mittleman (mittle@watson.ibm.com)
- J2-C28 T.J. Watson Research Center, PO Box 704, Yorktown Heights, NY 10598
-