From 5889959946084481575
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,cc5b2194d357e113
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 2003-02-21 12:34:30 PST
Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!kibo.news.demon.net!mutlu.news.demon.net!demon!mail2news.demon.co.uk!devnull
From: philippe_mori@hotmail.com ("Philippe Mori")
Newsgroups: comp.std.c++
Subject: Re: Virtual Base Constructors
Date: Fri, 21 Feb 2003 20:34:30 +0000 (UTC)
Organization: Bell Sympatico
Lines: 98
Approved: fjh@cs.mu.oz.au (Fergus Henderson , moderator of comp.std.c++)
Message-ID: <H4v5a.5837$hv3.558118@news20.bellglobal.com>
References: <58F604E3D17AD4119D8600508BE325060EA9A2F1@emss07m04.lmtas.lmco.com>
X-Trace: mail2news.demon.co.uk 1045859670 17 10.0.0.1 (21 Feb 2003 20:34:30 GMT)
X-Complaints-To: abuse@demon.net
NNTP-Posting-Date: Fri, 21 Feb 2003 20:34:30 +0000 (UTC)
X-Received: from mulga.cs.mu.oz.au ([128.250.1.22])
	by news.demon.co.uk with esmtp (Exim 4.05)
	id 18mJsK-000008-00
	for mail2news@news.news.demon.net; Fri, 21 Feb 2003 20:34:28 +0000
X-Received: from localhost (localhost [[UNIX: localhost]]) by mulga.cs.mu.OZ.AU
	id HAA11331; Sat, 22 Feb 2003 07:34:24 +1100 (EST)
X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f
X-Path: comp-std-cpp-robomod!not-for-mail
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
X-Delivered-To: std-c++@ncar.ucar.edu
X-Newsgroups: comp.std.c++
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.50.4133.2400
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400
X-NNTP-Posting-Date: Fri, 21 Feb 2003 14:27:35 EST
X-Spam-Status: No, hits=1.5 required=5.0
	tests=FORGED_HOTMAIL_RCVD,NOSPAM_INC,PRIORITY_NO_NAME,
	      QUOTED_EMAIL_TEXT,REFERENCES,SPAM_PHRASE_01_02
	version=2.43-cvs
X-Spam-Level: *
Xref: archiver1.google.com comp.std.c++:18008


> If a compiler can ascertain that a class with a virtual base isn't
> instantiable, wouldn't it be possible to allow that class to omit calling
> the constructor of the virtual base since it will have to be called by a
> more derived class anyway?
>
> For example,
>
> class Io_object {
> public:
>   virtual ~Io_object() {}
>   virtual void read_from(const Io_reader&) = 0;
>   virtual void write_to(const Io_writer&) const = 0;
> protected:
>   Io_object(const Io_type&);
> };
>
> class Base : public virtual Io_object {
> public:
>   void foo() = 0;
> protected:
>   Base(const Io_type& type) : Io_object(type) {}
> };
>
> class Concrete : public Base {
> };
>
> Do we really have to require that Base call the Io_object constructor even
> though it ultimately *has* to be handled by the Concrete type anyway?
>

Since you must currently calls Io_object from Concrete constructor (because
there are not default constructor in Io_Object) and you never create Base
object, I think that the compiler should allows that the constructor of a
virtual
base is not called from an intermediate class like Base.

If the user try to create an object of such a type, then it should be an
error
but otherwise, IMHO the compiler should ignore it (it should essentially
be considered as an abstract class if the class cannot be constructed
because a virtual base does not have default constructor and the
intermediate class (Base in exambple above) does not call it.

OTOH, I think that rules should be changed so that it will be possible to
call a virtual base constructor from an intermediate class and do not
specify it in the concrete type. The rule should be that the most derived
call to the virtual base constructor explicitly specified should be used
(default could be forced by calling a constructor with an empty argument
list).

Here some samples:

class VBase {
public:
    VBase(int);
    // VBase();
};

class Base : public VBase {
public:
    Base() : VBase(25) {}
    Base(int i) : VBase(i) {}

    // Does not compile if VBase is not un-commented
    Base(double d) : VBase() {}
};

class Der : public Base {
public:
    Der(int i) : Base(i) {}    // #1
    Der(int i, int j) : VBase(j), Base(i) { }    // #2
    Der() {}    // #3
    Der(double d) : Base(d) {}    // #4
};

#1 would calls VBase(i) --- even if VBase() is un-commented
#2 would calls VBase(j) --- as this is the case now
#3 would calls VBase(25) --- even if VBase() is un-commented
#4 would not compile. If VBase() is uncommented, calls it.

So essentially, starting from the most derived class, we uses the
first usable explicit call. If there is an ambiguity, an error occurs
except if the default constructor of VBase for the for the most
derived class (or a parent at a level where there are no ambiguity ---
that rule would be used if an intermediate class is a friend of the
virtual class).

Or he we want better backward compatibility, we may eventually
uses that extension only when there are no default constructor and
the most concrete type does not explicitly call it.

---
[ 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://www.jamesd.demon.co.uk/csc/faq.html                       ]



