From 2463177683519186427
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,3cdb654b702f7476
X-Google-Attributes: gidf78e5,public
X-Google-Thread: 109fba,3cdb654b702f7476
X-Google-Attributes: gid109fba,public
From: "Gerhard W. Gruber" <sparhawk@gmx.at>
Subject: Re: virtual functions
Date: 2000/08/18
Message-ID: <399B909C.654107BA@gmx.at>#1/1
X-Deja-AN: 659802629
Content-Transfer-Encoding: 7bit
Approved: Fergus Henderson <fjh@cs.mu.oz.au>, moderator of comp.std.c++
References: <399A78E4.8345D7B@gmx.at> <B5C01D64.93C3%anders@milkweed.com>
X-Accept-Language: en
X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f
Content-Type: text/plain; charset=us-ascii
X-Complaints-To: abuse@demon.net
X-Mail2News-Path: news.demon.net!mulga.cs.mu.oz.au
X-Trace: mail2news.demon.co.uk 966619272 mail2news:18281 mail2news mail2news.demon.co.uk
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
MIME-Version: 1.0
Newsgroups: comp.lang.c++,comp.std.c++

Anders Pytte wrote:

> The compiler will not allow you to call a non-static member function of an
> object that has not been constructed. Disappointing, isn't it? However,
> there are good reasons for this rule.
> 
> I've developed two techniques to accomplish what you are trying to do.
> 
> The first is to pass a function in a constructor's parameter list. Then the
> base class can call a function provided by the derived class. The function
> may not be a non-static member of the derived class, but it can be a static
> member function that takes a base class reference as a parameter.

I already tried this, but this brought me an "internal compiler error
please contact...". :) Also I consider this approach as somewhat ugly.
But it is better than nothing. :)

> My other approach has been to define a "post init" function in a base class
> which is called by public constructors of both the base and derived class.
> This requires awkward protected constructors in base classes that don't call
> the "post init" function and whose only purpose is to initialize the base
> sub-object in the derived object's constructor.

I'm not sure if I understand this right, but I think that I implemented
it that way. This resulted in multiple calls to the init function.
That's not really nice, but I can live with it, if there is no other way
around. Another idea I had was to use to a bit of assembly code to
enforce the initialization, but that's even worse. :)

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]




