Re: Suggestion

From: Alf P. Steinbach (alfps_at_start.no)
Date: 09/07/04


Date: Tue, 07 Sep 2004 03:26:32 GMT


* Eivind Grimsby Haarr:
>
> When using polymorphism in a big system, I have sometimes come across
> problems when changing the signature of the function in the base class,
> and forgetting to change the signature of the derived functions
> accordingly. (Most often when only some of the derived classes redefine
> it.) Accessing the objects with base class pointers, the version in the
> base class is called, which is not what I wanted. This is most often very
> difficult to detect.
>
> This has made me come up with an idea for a compiler/language feature that
> would fix this problem: A keyword in front of the derived function that
> says that this function is derived from a base class, and the compiler
> should issue an error if a function with a similar signature doesn't
> exist in one of the base classes.
>
> What do you think about this idea? Is it just too much pain for a rare
> problem?

It's always a good idea to catch errors at the earliest time possible,
preferably analysis and design, but if not, then compile-time.

Your idea is a Good One (TM) and is implemented in .NET languages such as
VB.NET and C#, in the latter using the keywords "override" (override) and
"new" (shadow).

Getting it into C++, that's another matter... ;-)

-- 
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?


Relevant Pages

  • Re: Suggestion
    ... > problems when changing the signature of the function in the base class, ... (Most often when only some of the derived classes redefine ... Accessing the objects with base class pointers, ... where I've seen a few TDD groups fall short from inexperience. ...
    (comp.lang.cpp)
  • Re: Default arguments, etc ..
    ... > Is there a way to declare a variadiac function in a Base class? ... You should have no problem declaring a variadic function in a base class, ... This signature obviously does not match the signature 'function taking two ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Default arguments, etc ..
    ... >> You should have no problem declaring a variadic function in a base class, ... >> nor should overriding such a function pose problems. ... >> This signature obviously does not match the signature 'function taking ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Difference between C#s "new" keyword and VB.NETs "shadows" keyword
    ... > particular function does in fact differ in signature to the function ... > programmer, ... the base class methods through reflection. ...
    (microsoft.public.dotnet.languages.csharp)

Loading