home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!gatech!news.byu.edu!hamblin.math.byu.edu!sol.ctr.columbia.edu!spool.mu.edu!umn.edu!csus.edu!borland.com!pete
- From: pete@borland.com (Pete Becker)
- Subject: Re: Overriding the order of constructors?
- Message-ID: <1992Dec14.181823.6474@borland.com>
- Originator: pete@genghis.borland.com
- Keywords: constructor ordering
- Sender: news@borland.com (News Admin)
- Organization: Borland International
- References: <1992Dec13.220943.22047@jarvis.csri.toronto.edu> <robison1.724307343@husc10>
- Date: Mon, 14 Dec 1992 18:18:23 GMT
- Lines: 33
-
- In article <robison1.724307343@husc10> robison1@husc10.harvard.edu (Keith Robison) writes:
- >dembo@csri.toronto.edu (Prof. Ron Dembo) writes:
- >
- >
- >
- >>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?
- >
- >
- > I believe you can effectively accomplish this dangerous
- >goal by calling virtual functions in your constructors:
- >
- >
- >class A {
- > A() { reroute(); do_A_ctor_stuff(); }
- > virtual void reroute(); { }
- >}
- >
- >class B : public A {
- > B() {}
- > void reroute () { do_B_ctor_stuff(); }
- >}
- >
- >
- >This will cause B's reroute() to be executed before any
- >A constructing has occurred.
- >
-
- This won't work. Virtual functions are effectively non-virtual when
- called from a constructor or a destructor. If they weren't, you could call
- a member function on an uninitialized object.
-