home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!well!johnrp
- From: johnrp@well.sf.ca.us (John Panzer)
- Subject: Re: Overriding the order of constructors?
- Message-ID: <Bz8oGx.B7x@well.sf.ca.us>
- Keywords: constructor ordering
- Sender: news@well.sf.ca.us
- Organization: Whole Earth 'Lectronic Link
- References: <1992Dec13.220943.22047@jarvis.csri.toronto.edu> <robison1.724307343@husc10>
- Date: Mon, 14 Dec 1992 07:50:57 GMT
- Lines: 40
-
- 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.
- >
-
- Are you certain? I believe that A::reroute() will
- be called if reroute() is called from within A's
- constructor or destructor. I think this is a
- common C++ "gotcha" - it's certainly gotten me
- in the past.
-
- John Panzer
- johnrp@well.sf.ca.us
-
-
-