🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.mac.programmer.codewarrior
Article #13

Re: C++ comment on warnings about overloaded functions (Bug?)

#13
From: MW Ron
Date: Wed, 18 Oct 1995 22:05
73 lines
2529 bytes
 julian@cs.auckland.ac.nz (Julian Harris) 

This following code does give a Warning  message
Warning : function declaration hides inherited virtual function
atest.cpp line 23   {

when all the warnings are selected in the preferences
Ron

METROWERKS                   Ron Liechty
"Software at Work"    MWRon@metrowerks.com
----------------- your message ------------

Version: MW IDE 1.3, 68k C++ 1.3 running under System 7.5.1 on Quadra 700.
Reproducability: ALWAYS
Type: gotcha :)

Take this code below. The subclassed virtual function omits the 'const'.
This appears to MW C++ as a new overloaded function (even though this is
the only difference) and hence the 'OverrideMe()' function doesn't behave
polymorphically as one may at first look expect.

Most compilers return a warning when a subclass overloads a parent
function that differs only in return type. Could I suggest that when the
return type differs only in 'const' that this could be flagged as a
warning as well?

FYI, gnu g++ 2.7.0 also gives similar results.


----
#include <iostream.h>

template< class X > class T
    {
    public:
        virtual void    CallMe( X a )
                            {
                            cout << "CallMe from T" << a << endl;
                            OverrideMe( a );
                            }
    protected:              
        virtual void    OverrideMe( X a ) const
                            {
                            cout << "OverrideMe from T" << a << endl;
                            }
    };



class Derived: public T<int>
    {
    public:
        virtual void    OverrideMe( int da )
                            {
                            cout << "OverrideMe from Derived" << da <<
endl;
                            }
    };



int main( void ) {
    T<int> *p = new Derived();
    Derived q;
    T<int> r( q );
    
    p->CallMe( 4 );
    q.CallMe( 5 );
    r.CallMe( 6 );
    
    return 0;
}
Technical Details
Message-ID: <463tnt$7ih@newsbf02.news.aol.com>
Path: arc1-ca.pugleaf.net!newsbf02.news.aol.com!not-for-mail
References: <julian-1810951406510001@julian.cs.auckland.ac.nz>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!newsbf02.news.aol.com!not-for-mail
From: mwron@aol.com (MW Ron)
Newsgroups: comp.sys.mac.programmer.codewarrior,comp.lang.c++
Subject: Re: C++ comment on warnings about overloaded functions (Bug?)
Date: 18 Oct 1995 18:05:49 -0400
Organization: America Online, Inc. (1-800-827-6364)
Sender: root@newsbf02.news.aol.com
Message-ID: <463tnt$7ih@newsbf02.news.aol.com>
References: <julian-1810951406510001@julian.cs.auckland.ac.nz>
Reply-To: mwron@aol.com (MW Ron)
NNTP-Posting-Host: newsbf02.mail.aol.com