This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

c++/8821: gcc 3.2 problem with overloaded inherited operator


>Number:         8821
>Category:       c++
>Synopsis:       gcc 3.2 problem with overloaded inherited operator
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          rejects-legal
>Submitter-Id:   net
>Arrival-Date:   Thu Dec 05 05:06:00 PST 2002
>Closed-Date:
>Last-Modified:
>Originator:     Andre Mueller
>Release:        gcc version 3.2
>Organization:
>Environment:
Linux version 2.4.19-4GB
>Description:
A operator with a user class from a base class A will not 
be found if a derived class B overloads this operator.

> g++ tst.cpp
tst.cpp: In function `int main(int, char**)':
tst.cpp:16: no match for `B& << Z&' operator
tst.cpp:10: candidates are: void B::operator<<(int)
>How-To-Repeat:
class Z {   };

class A  {
public:
    void operator << ( const Z  & ) { }
};
  
class B : public A {
public:
    void operator << ( int ) {  }
}; 
  
int main( int , char ** ) {
    B   b;
    Z   z;
    b << z;     // Oops!? Why is it not possible to compile this?
    return 0;
}
>Fix:
An explicit downcast is necessary:
Replace the line
  b << z
with
 static_cast<A&>(b) << z;
>Release-Note:
>Audit-Trail:
>Unformatted:


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]