🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.sys.mac.programmer.codewarrior
3 messages
3 total messages Started by Julian Harris Wed, 18 Oct 1995 01:06
C++ comment on warnings about overloaded functions (Bug?)
#12
Author: Julian Harris
Date: Wed, 18 Oct 1995 01:06
66 lines
2506 bytes
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;
}

-- 
.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .
Microsoft is not the answer.                    >  Julian Harris, Programmer   >
Microsoft is the question.                     >  Comp. Sci. Dept.     x8915  >
                                              >  The University of Auckland  >
NO is the answer.                            >  julian@cs.auckland.ac.nz    >
Re: C++ comment on warnings about overloaded functions (Bug?)
#13
Author: 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;
}
Re: C++ comment on warnings about overloaded functions (Bug?)
#14
Author: Andy Dent
Date: Thu, 19 Oct 1995 13:42
36 lines
1706 bytes
In article <julian-1810951406510001@julian.cs.auckland.ac.nz>,
julian@cs.auckland.ac.nz (Julian Harris) wrote:

>Type: gotcha :)
Agreed - a warning would be nice
>
>Take this code below. The subclassed virtual function omits the 'const'.
>This appears to MW C++ as a new overloaded function 

>Could I suggest that when the
>return type differs only in 'const' that this could be flagged as a
>warning as well?

You're confusing things here. The const after the function parameters has
nothing to do with the return type. Each method has an implied first
parameter of 'this' so const has the effect:

void someClass::A(int b) 
can be read as (parameter-wise)
void  A(someClass&, int b)


so 
void someClass::A(int b) const 
varies in the first parameter
void  A(const someClass&, int b)


IN GENERAL, CodeWarrior 1.3 seems a bit shaky when the only difference
between parameters is constness. (When I've time to produce a clear bug
report I will.)

Andy Dent, Product Architect, A.D. Software, Western Australia
OOFILE - "the cross-platform OODBMS that speaks c++"
ftp://ftp.highway1.com.au/pub/adsoftware/oofile/
http://www.highway1.com.au/adsoftware/oofile.html
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads