home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / lang / cplus / 13654 < prev    next >
Encoding:
Text File  |  1992-09-14  |  1.6 KB  |  60 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!wupost!m.cs.uiuc.edu!sunb10.cs.uiuc.edu!sparc10.cs.uiuc.edu!pjl
  3. From: pjl@sparc10.cs.uiuc.edu (Paul Lucas)
  4. Subject: Re: Problems with constructor in C++
  5. Message-ID: <1992Sep15.030705.13864@sunb10.cs.uiuc.edu>
  6. Sender: news@sunb10.cs.uiuc.edu
  7. Organization: University of Illinois at Urbana-Champaign
  8. References: <1992Sep14.225041.15692@access.usask.ca>
  9. Distribution: na
  10. Date: Tue, 15 Sep 1992 03:07:05 GMT
  11. Lines: 47
  12.  
  13. In <1992Sep14.225041.15692@access.usask.ca> srikant@skorpio.usask.ca (Srikant Subramaniam) writes:
  14.  
  15. >Hello Netters:
  16.  
  17. >I have a rather peculiar problem with constructors in C++. In the code
  18. >fragment below, the constructor for AtomicInt is not executed at all.
  19.  
  20. >File chore.h
  21. >------------
  22.  
  23. >Class Chore : public DLINK {
  24.  
  25. >    ......
  26. >    .......
  27.  
  28. >    AtomicInt numworkers;
  29. >public: Chore ( .......) {
  30. >    
  31. >    }
  32. >} // Class Chore
  33.  
  34. >File atomic_int.h
  35. >------------------
  36.  
  37. >Class AtomicInt {
  38.  
  39. >    ...........
  40.  
  41. >    AtomicInt() { .......}
  42. >    AtomicInt(int x) { ......}
  43. >    AtomicInt(AtomicInt& x) { .......}
  44. >}
  45.  
  46. >When the code is executed, the constructor for AtomicInt doesn't get executed
  47. >at all. My understanding of C++ was that when the initialization is done as
  48. >in AtomicInt numworkers, the constructor is automatically executed. I hope I'm
  49. >not wrong :-(
  50.  
  51. >Could somebody out in net.land  clarify this ?
  52.  
  53. *****>    You are correct.  The default constructor will (should) be called.
  54.     (BTW, I assume you meant "class" not "Class"?)  Why doesn't it
  55.     work then....don't know.
  56. -- 
  57.     - Paul J. Lucas                University of Illinois    
  58.       AT&T Bell Laboratories        at Urbana-Champaign
  59.       Naperville, IL            pjl@cs.uiuc.edu
  60.