home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!spool.mu.edu!agate!tfs.com!tfs.com!eric
- From: eric@tfs.com (Eric Smith)
- Subject: Re: Problems with constructor in C++
- Message-ID: <1992Sep15.083100.17828@tfs.com>
- Organization: TFS
- References: <1992Sep14.225041.15692@access.usask.ca> <1992Sep15.030705.13864@sunb10.cs.uiuc.edu>
- Distribution: na
- Date: Tue, 15 Sep 1992 08:31:00 GMT
- Lines: 55
-
- In article <1992Sep15.030705.13864@sunb10.cs.uiuc.edu> pjl@sparc10.cs.uiuc.edu (Paul Lucas) writes:
- >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
-
-
- Maybe no Chore object ever gets constructed, because no Chore objects
- are declared or allocated? And maybe AtomicInt is only used in
- Chore. Thus it would be correct for no constructors to be invoked.
- Unless we see the actual code, we can only guess. (And the typos prove
- this isn't the actual code.)
-