From 1773733450852839384
X-Google-Language: ENGLISH,ASCII
X-Google-Thread: f78e5,ccbfcafab96cf493
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 2001-11-26 11:37:02 PST
Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!dispose.news.demon.net!news.demon.co.uk!demon!mail2news.demon.co.uk!not-for-mail
From: "axter" <news@axter.com>
Newsgroups: comp.std.c++
Subject: Re: Proposol to increase robustness of programs
Date: Mon, 26 Nov 2001 19:36:41 GMT
Organization: Excite@Home - The Leader in Broadband http://home.com/faster
Approved: Fergus Henderson <fjh@cs.mu.oz.au>, moderator of comp.std.c++
Message-ID: <aJjM7.257938$5A3.97435266@news1.rdc2.pa.home.com>
References: <3BFE97B3.91430FB1@wanadoo.fr>
X-Trace: mail2news.demon.co.uk 1006803406 mail2news:9243 mail2news mail2news.demon.co.uk
X-Complaints-To: abuse@demon.net
X-Mail2News-Path: news.demon.net!mulga.cs.mu.oz.au
X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2600.0000
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
NNTP-Posting-Date: Sun, 25 Nov 2001 20:40:38 PST
Lines: 86
Xref: archiver1.google.com comp.std.c++:8303

If you had made function f() a pure virtual function, you could avoid this
problem.

"Lo�c Joly" <loic.actarus.joly@wanadoo.fr> wrote in message
news:3BFE97B3.91430FB1@wanadoo.fr...
Hello everybody,
This is my first post on this group, so I hope I am on-topic...

I would like to make a proposal for an addition to the C++ standard.
It pertains with virtual function that we want to be sure exist in the
base class.

Motivation :
struct A
{
  virtual void f(char *s);
};

struct B : A
{
  virtual void f(char *s);
};

int main ()
{
  A* a = new B;
  a->f();
}

This works just fine, but now, suppose someone in charge of maintaining
the A class discovers that the declaration of f should have been :
virtual void f(char const *s);
He makes the change, but somehow forget to change class B. The compiler
will compile silently, but the program will not do the expected thing.
This is a real-world example that has already bitten me several times,
and is difficult to debug.


Proposal :
Add something that will prevent compilation if a virtual function does
not have a function to override in the base class.
Some notation (with comments) may be :

struct B : A
{
  override virtual void f(char *s);
};

This syntax seems rather clear to me, but requires a new keyword, and
thus may break old programs (maybe we should give to 'static' yet
another signification ;)).
The good point is that is is very easy to compile this code on old (i.e.
current) compilers (just #define away the override keyword).

struct B : A
{
  virtual void f(char *s) = 1;
}

This syntax is not so clear, more difficult to #define away, but does
not require any new keyword. It also has the advantage of giving more
consistance to the existing virtual =0 syntax ;).




I would like to know what do you think of this proposal; and if there is
something I can do to make it accepted in the next standard, I would
like to have some advise about it.

--
Lo�c

---
[ 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.research.att.com/~austern/csc/faq.html                ]


---
[ 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.research.att.com/~austern/csc/faq.html                ]



