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

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!haven.umd.edu!darwin.sura.net!wupost!gumby!destroyer!ubc-cs!unixg.ubc.ca!kakwa.ucs.ualberta.ca!access.usask.ca!skorpio!srikant
  3. From: srikant@skorpio.usask.ca (Srikant Subramaniam)
  4. Subject: Problems with constructor in C++
  5. Message-ID: <1992Sep14.225041.15692@access.usask.ca>
  6. Sender: srikant@skorpio (Srikant Subramaniam)
  7. Nntp-Posting-Host: skorpio.usask.ca
  8. Organization: University of Saskatchewan, Saskatoon, Canada
  9. Date: Mon, 14 Sep 1992 22:50:41 GMT
  10. Lines: 48
  11.  
  12. Hello Netters:
  13.  
  14. I have a rather peculiar problem with constructors in C++. In the code
  15. fragment below, the constructor for AtomicInt is not executed at all.
  16.  
  17. File chore.h
  18. ------------
  19.  
  20. Class Chore : public DLINK {
  21.  
  22.     ......
  23.     .......
  24.  
  25.     AtomicInt numworkers;
  26. public: Chore ( .......) {
  27.     
  28.     }
  29. } // Class Chore
  30.  
  31. File atomic_int.h
  32. ------------------
  33.  
  34. Class AtomicInt {
  35.  
  36.     ...........
  37.  
  38.     AtomicInt() { .......}
  39.     AtomicInt(int x) { ......}
  40.     AtomicInt(AtomicInt& x) { .......}
  41. }
  42.  
  43. When the code is executed, the constructor for AtomicInt doesn't get executed
  44. at all. My understanding of C++ was that when the initialization is done as
  45. in AtomicInt numworkers, the constructor is automatically executed. I hope I'm
  46. not wrong :-(
  47.  
  48. Could somebody out in net.land  clarify this ?
  49.  
  50. ----- 
  51.  |\/\/\/|      Srikant Subramaniam.
  52.  |      |      srikant@cs.usask.ca 
  53.  |    |
  54.  |      |      Disclaimer: This is not what really I look like.     
  55.  | (o)(o)      Disclaimer: I didn't do it, nobody saw me do it, 
  56.  C      _)                  can't prove anything. 
  57.   | ,___|             
  58.   |   /     
  59.   /---\    
  60.