home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / cplus / 12989 < prev    next >
Encoding:
Text File  |  1992-08-27  |  1.5 KB  |  43 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!stanford.edu!agate!linus!linus.mitre.org!schaffner
  3. From: sch@mitre.org (Stu Schaffner)
  4. Subject: Re: Constructors in C++
  5. Message-ID: <sch-270892163047@schaffner.mitre.org>
  6. Followup-To: comp.lang.c++
  7. Sender: news@linus.mitre.org (News Service)
  8. Nntp-Posting-Host: schaffner.mitre.org
  9. Organization: MITRE Corp.
  10. References: <1992Aug27.155652.11995@kakwa.ucs.ualberta.ca>
  11. Date: Thu, 27 Aug 1992 20:40:27 GMT
  12. Lines: 29
  13.  
  14. In article <1992Aug27.155652.11995@kakwa.ucs.ualberta.ca>,
  15. jimmy@namao.ucs.ualberta.ca  wrote:
  16. > Does a constructor with parameters call the default constructor ? I am
  17. > a novice, so please do not laugh.
  18. > Thanks,
  19. > Jimmy
  20. > jimmy@namao.ucs.ualberta.ca
  21. > --
  22. > jimmy@namao.ucs.ualberta.ca
  23.  
  24. Nothing to laugh about ... there are a number of subtleties associated with
  25. constructors.  The short answer is no, nor should you call the default
  26. constructor explicitly in the nondefault constructor. Recall that a
  27. constructor really does two things in sequence:  initialize the object
  28. enough that methods can be called, then execute a constructor body. A call
  29. in that body to another initializer would repeat the initialization.
  30.  
  31. There is a good explanation of all of this in Ellis & Stroustrup, "The
  32. Annotated C++ Reference Manual", sometimes called "the ARM" (ISBN
  33. 0-201-51459-1.  In the 1990 version, at least, it starts on page 262. This
  34. also gives an example of how to factor out code common to more than one
  35. constructor.
  36.  
  37. Stu Schaffner, not speaking for
  38. The MITRE Corp.
  39. sch@mitre.org
  40.