public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: c++/3400: doesn't compile simple hierarchy with overlaoding
@ 2001-06-26  1:16 Artem Khodush
  0 siblings, 0 replies; 3+ messages in thread
From: Artem Khodush @ 2001-06-26  1:16 UTC (permalink / raw)
  To: nobody; +Cc: gcc-prs

The following reply was made to PR c++/3400; it has been noted by GNATS.

From: "Artem Khodush" <artem@duma.gov.ru>
To: <volker.reichenberger@iwr.uni-heidelberg.de>
Cc: <gcc-gnats@gcc.gnu.org>, <gcc-bugs@gcc.gnu.org>
Subject: Re: c++/3400: doesn't compile simple hierarchy with overlaoding
Date: Tue, 26 Jun 2001 11:56:20 +0400

 > 
 > class A {public: void a() {};};class B: public A {public: void a(int n) {};};int main(void){ B b; b.a(); return 0;}
 > 
 > I get the error message:
 > 
 > test.cc: In function `int main()':
 > test.cc:15: no matching function for call to `B::a ()'
 > test.cc:8: candidates are: void B::a(int)
 > 
 > I believe the code is correct (so do all my colleagues). 
 
 Nope. See the quote from the c++ standard below. In GCC 3.0,
 you can fix the code by putting 
   using A::a();
 into the class B.
 
   13.2  Declaration matching                                  [over.dcl]
 
 1 Two function declarations of the same name refer to the same  function
   if  they  are in the same scope and have equivalent parameter declara-
   tions (_over.load_).  A function member of a derived class is  not  in
   the  same scope as a function member of the same name in a base class.
   [Example:
 
           class B {
           public:
               int f(int);
           };
 
           class D : public B {
           public:
               int f(char*);
           };
   Here D::f(char*) hides B::f(int) rather than overloading it.
           void h(D* pd)
           {
               pd->f(1);       // error:
                               // D::f(char*) hides B::f(int)
               pd->B::f(1);    // ok
               pd->f("Ben");   // ok, calls D::f
           }
    --end example]
 
 
 
 


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: c++/3400: doesn't compile simple hierarchy with overlaoding
@ 2001-06-26  5:26 lerdsuwa
  0 siblings, 0 replies; 3+ messages in thread
From: lerdsuwa @ 2001-06-26  5:26 UTC (permalink / raw)
  To: gcc-bugs, gcc-prs, nobody, volker.reichenberger

Synopsis: doesn't compile simple hierarchy with overlaoding

State-Changed-From-To: open->closed
State-Changed-By: lerdsuwa
State-Changed-When: Tue Jun 26 05:26:16 2001
State-Changed-Why:
    Not a bug.

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view&pr=3400&database=gcc


^ permalink raw reply	[flat|nested] 3+ messages in thread

* c++/3400: doesn't compile simple hierarchy with overlaoding
@ 2001-06-25  4:16 volker.reichenberger
  0 siblings, 0 replies; 3+ messages in thread
From: volker.reichenberger @ 2001-06-25  4:16 UTC (permalink / raw)
  To: gcc-gnats

>Number:         3400
>Category:       c++
>Synopsis:       doesn't compile simple hierarchy with overlaoding
>Confidential:   no
>Severity:       critical
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          rejects-legal
>Submitter-Id:   net
>Arrival-Date:   Mon Jun 25 04:16:01 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     Volker Reichenberger
>Release:        gcc version 2.95.2 19991024 (release)
>Organization:
>Environment:
SuSe Linux 7.2 on IBM Thinkpad A21p
>Description:
When trying to compile the program

class A {public:	void a() {};};class B: public A {public:	void a(int n) {};};int main(void){	B b;	b.a();	return 0;}

I get the error message:

test.cc: In function `int main()':
test.cc:15: no matching function for call to `B::a ()'
test.cc:8: candidates are: void B::a(int)

I believe the code is correct (so do all my colleagues). Changing the method name to 'b()' (or anything else) fixes the problem.  The code snippet does not exhibit good programming style, but nonetheless it seems to be correct.

C++ books in my reach gave no help on the subject.
>How-To-Repeat:
Compile code with g++
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2001-06-26  5:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-06-26  1:16 c++/3400: doesn't compile simple hierarchy with overlaoding Artem Khodush
  -- strict thread matches above, loose matches on Subject: below --
2001-06-26  5:26 lerdsuwa
2001-06-25  4:16 volker.reichenberger

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).