From 7903637182451089126 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f78e5,ccbfcafab96cf493 X-Google-Attributes: gidf78e5,public X-Google-ArrivalTime: 2001-12-04 11:38:02 PST Path: archiver1.google.com!news2.google.com!news1.google.com!newsfeed.stanford.edu!newsfeed.gamma.ru!Gamma.RU!dispose.news.demon.net!news.demon.co.uk!demon!mail2news.demon.co.uk!not-for-mail From: Michiel Salters Newsgroups: comp.std.c++ Subject: Re: Proposol to increase robustness of programs Date: Tue, 4 Dec 2001 19:37:31 GMT Organization: http://www.newsranger.com Approved: Fergus Henderson , moderator of comp.std.c++ Message-ID: References: <3BFE97B3.91430FB1@wanadoo.fr> <3C0290D3.DA98AAC0@wanadoo.fr> X-Trace: mail2news.demon.co.uk 1007494656 mail2news:24162 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-Abuse-Info: When contacting newsranger.com regarding abuse please X-Abuse-Info: forward the entire news article including headers or X-Abuse-Info: else we will not be able to process your request NNTP-Posting-Date: Tue, 04 Dec 2001 09:29:08 EST X-Abuse: abuse@jtwis.com X-Added: Message sent through jtwis.com at 2001-12-04 09:29:48 Lines: 71 Xref: archiver1.google.com comp.std.c++:8464 In article <3C0290D3.DA98AAC0@wanadoo.fr>, =?iso-8859-1?Q?Lo=EFc?= Joly says... >Michiel Salters wrote: >> In article <3BFE97B3.91430FB1@wanadoo.fr>, =3D?iso-8859-1?Q?Lo=3DEFc?=3D= >> Joly says... >> >Motivation : >> >struct A >> >{ >> > virtual void f(char *s); >> >}; >> > >> >struct B : A >> >{ >> > virtual void f(char *s); >> >}; >> >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. >> I expect a compiler to give a warning for this. Warnings are QOI, >> though, >> not mandated by the standard. If all compilers would give a warning, do >> you think a language change is still in order ? > >Yes I do, because there are some case when we want to define a new >virtual function in a derived class, and some case when we want to >override an existing one. >Thus, if I want all warnings to be removed in the final version of the >code (and I usually want that), I will have to tell somehow that it is >okay if this function is a new function, but not if that function is a >new one. >So I would have to add a compiler-specific flag (#prama, or something >else) to tell it what kind of function it is. I thought this was a good argument, but on second thinking I disagree. class A { virtual void f( const char* ); }; class B : public A { virtual void f( char* ); }; and you get a warning about B::f hiding A::f (which was you intended). And the compiler is right, because when you have B b; A* ptr_b=&b; char buf[16]; b.f(buf); ptr_b->f(buf); you call an f method of the B object twice, with the same parameter, but you get two different methods. I think that warning should be fixed. Regards, -- Michiel Salters Consultant Technical Software Engineering CMG Trade, Transport & Industry Michiel.Salters@cmg.nl --- [ 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 ]