public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: andre@kiwisound.de
To: gcc-gnats@gcc.gnu.org
Subject: c++/8821: gcc 3.2 problem with overloaded inherited operator
Date: Thu, 05 Dec 2002 05:06:00 -0000	[thread overview]
Message-ID: <20021205125608.2219.qmail@sources.redhat.com> (raw)


>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:


             reply	other threads:[~2002-12-05 13:06 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-12-05  5:06 andre [this message]
2002-12-10 14:28 bangerth
2002-12-11  1:42 reichelt
2002-12-11  7:16 Nathan Sidwell
2002-12-11  7:26 Wolfgang Bangerth

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20021205125608.2219.qmail@sources.redhat.com \
    --to=andre@kiwisound.de \
    --cc=gcc-gnats@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).