home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!ftpbox!mothost!lmpsbbs!supra.comm.mot.com!rittle
- From: rittle@supra.comm.mot.com (Loren James Rittle)
- Subject: Use of constructor within class declaration
- Organization: Land Mobile Products Sector, Motorola Inc.
- Date: Fri, 24 Jul 1992 23:29:26 GMT
- Message-ID: <1992Jul24.232926.18488@lmpsbbs.comm.mot.com>
- Sender: rittle@comm.mot.com (Loren J. Rittle)
- Nntp-Posting-Host: 145.1.80.40
- Lines: 43
-
- Hello net friends,
-
- Can anyone explain what is happening below? Why can I not use a class'
- constructor as a default argument in a function defined in a class? Is
- there a good way around this problem (other than moving the function
- definition out of the class OR using overloading)? Does any version of
- AT&T C++ fix this problem (I can find no reference in the 'BS' C++
- manual about this. I'm just learning C++ so I may have missed something)?
-
- A person I work with claims that even if I could use a constructor as I
- wish, it would be bad style. What is your opinion? To me it is as
- natural to want to use a constructor anywhere in the class declaration
- after it is declared as it is to refer to a class' members later within
- the class declaration.
-
- The example has been kept short in the hopes that someone will take the
- time to respond. Thanks for email or posted responses that can be
- summerized upon demand.
-
- Regards,
- Loren
-
- $ gcc test2.C # gcc 2.2.2
- test2.C:7: type `point' is not yet defined
- $ cxx test2.C # DEC cxx 2.1
- test2.C:7: error: In this declaration, "point" is an incomplete or
- function type and so cannot be the target type of a conversion.
- Compilation terminated with errors.
-
- - --- begin test2.C ---
- class point
- {
- double _x, _y;
- public:
- point (double x = 0.0, double y = 0.0) : _x(x), _y(y) {}
- #if 1
- double distance (point o = point (0.0, 0.0)) { return /* ... */ 0.0; }
- #else
- double distance (point o) { return /* ... */ 0.0; }
- double distance (void) { return /* ... */ 0.0; }
- #endif
- };
- - --- end test2.C ---
-