This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
c++/8821: gcc 3.2 problem with overloaded inherited operator
- From: andre at kiwisound dot de
- To: gcc-gnats at gcc dot gnu dot org
- Date: 5 Dec 2002 12:56:08 -0000
- Subject: c++/8821: gcc 3.2 problem with overloaded inherited operator
- Reply-to: andre at kiwisound dot de
>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: