Re: virtual keyword for the derived class
From: Karl Heinz Buchegger (kbuchegg_at_gascad.at)
Date: 07/20/04
- Next message: jeffc: "Re: C++: 4 paradigms?"
- Previous message: jeffc: "Re: C++: 4 paradigms?"
- In reply to: Siemel Naran: "Re: virtual keyword for the derived class"
- Next in thread: Rolf Magnus: "Re: virtual keyword for the derived class"
- Reply: Rolf Magnus: "Re: virtual keyword for the derived class"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 20 Jul 2004 17:46:20 +0200
Siemel Naran wrote:
>
> "Rolf Magnus" <ramagnus@t-online.de> wrote in message
> news:cdikj1$31k$05$2@news.t-
>
> > The main point is that you can see that the function is virtual without
> > having to look into the base class first (or the base's base or the
> > base's base's base or wherever it was initially declared virtual).
> > IMHO it would be better if C++ required the virtual keyword in this
> > place.
>
> It is possible the function is not virtual in the base class, but is in the
> derived class, so strictly speaking the virtual tells us little other than
> the function is virtual in this and further derived classes. It would also
> have been nice if C++ prohibited this too, as I've never seen it used.
My personal favourite would have been to have 2 keywords:
one for the 'start of the virtual chain'
one for 'continuation of the virtual chain'
Then the whole things becomes
class Base
{
virtual_start void foo();
};
class Derived
{
virtual_cont void foo();
};
The compiler then could check in the case of virtual_cont that in the Base
class (or the Base of the Base) the very same function is declared virtual_start.
If not -> Error
If on the other hand, the keyword virtual_cont is left out, this could also be
consider to be an error, if the Base class declared this function to be virtual_start
Why?
Because in the real world it happens, that one has to turn a normal function into
a virtual one and vice versa). The consequences of doing that can be dramatic, thus
each class deriving from that class need to checked if the behaviour of that function
is still ok. Currently the compiler has no way to help with doing that. It silently
transforms derived class functions into virtual ones.
-- Karl Heinz Buchegger kbuchegg@gascad.at
- Next message: jeffc: "Re: C++: 4 paradigms?"
- Previous message: jeffc: "Re: C++: 4 paradigms?"
- In reply to: Siemel Naran: "Re: virtual keyword for the derived class"
- Next in thread: Rolf Magnus: "Re: virtual keyword for the derived class"
- Reply: Rolf Magnus: "Re: virtual keyword for the derived class"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]