home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!wupost!m.cs.uiuc.edu!sunb10.cs.uiuc.edu!sparc10.cs.uiuc.edu!pjl
- From: pjl@sparc10.cs.uiuc.edu (Paul Lucas)
- Subject: Re: Problems with constructor in C++
- Message-ID: <1992Sep15.030705.13864@sunb10.cs.uiuc.edu>
- Sender: news@sunb10.cs.uiuc.edu
- Organization: University of Illinois at Urbana-Champaign
- References: <1992Sep14.225041.15692@access.usask.ca>
- Distribution: na
- Date: Tue, 15 Sep 1992 03:07:05 GMT
- Lines: 47
-
- In <1992Sep14.225041.15692@access.usask.ca> srikant@skorpio.usask.ca (Srikant Subramaniam) writes:
-
- >Hello Netters:
-
- >I have a rather peculiar problem with constructors in C++. In the code
- >fragment below, the constructor for AtomicInt is not executed at all.
-
- >File chore.h
- >------------
-
- >Class Chore : public DLINK {
-
- > ......
- > .......
-
- > AtomicInt numworkers;
- >public: Chore ( .......) {
- >
- > }
- >} // Class Chore
-
- >File atomic_int.h
- >------------------
-
- >Class AtomicInt {
-
- > ...........
-
- > AtomicInt() { .......}
- > AtomicInt(int x) { ......}
- > AtomicInt(AtomicInt& x) { .......}
- >}
-
- >When the code is executed, the constructor for AtomicInt doesn't get executed
- >at all. My understanding of C++ was that when the initialization is done as
- >in AtomicInt numworkers, the constructor is automatically executed. I hope I'm
- >not wrong :-(
-
- >Could somebody out in net.land clarify this ?
-
- *****> You are correct. The default constructor will (should) be called.
- (BTW, I assume you meant "class" not "Class"?) Why doesn't it
- work then....don't know.
- --
- - Paul J. Lucas University of Illinois
- AT&T Bell Laboratories at Urbana-Champaign
- Naperville, IL pjl@cs.uiuc.edu
-