home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!utcsri!csri.toronto.edu!dembo
- Newsgroups: comp.lang.c++
- From: dembo@csri.toronto.edu (Prof. Ron Dembo)
- Subject: Overriding the order of constructors?
- Message-ID: <1992Dec13.220943.22047@jarvis.csri.toronto.edu>
- Summary: Why can I not explicitly override the ordering of initilization
- Keywords: constructor ordering
- Date: 14 Dec 92 03:09:43 GMT
- Lines: 54
-
-
-
- What is the rational for not allowing a programmer to override the
- default calling order of constructors and initializers? I see
- the importance of having a well defined default. However, why
- shouldn't the ordering of the initilizers be significant? In
- the code below what I would have liked to see would be
- -----------
- B
- A
- C
- -----------
- rather than
- -----------
- A
- B
- C
- -----------
- #include <iostream.h>
-
- class A
- {
- public :
- A(void)
- {
- cerr << "A\n";
- }
- };
-
- class B
- {
- public :
- B(void)
- {
- cerr << "B\n";
- }
- };
-
- class C : public A
- {
- B b;
-
- public :
-
- C(void) : b(), A()
- {
- cerr << "C\n";
- }
- };
-
- main()
- {
- C x;
- }
-