Overloaded methods.

Gabriel Dos_Reis Gabriel.Dos_Reis@sophia.inria.fr
Thu Sep 30 19:57:00 GMT 1999


Alexander Zvyagin <zvyagin@gams.ihep.su> writes:

| Dear GCC developerc,
| 
| please take a look at the code:
| 
| class A
| {
|   public:
|             void f(void);
|     virtual void f(char);
| };
| 
| class B: public A { public: void f(char); };
| 
| void B::f(char c)
| {
|   A::f();  // OK.
|   f();     // The same function as above. ERROR. Is it a bug?
| }
| 
| $ g++ -c b.c
| b.c: In method `void B::f(char)':
| b.c:13: no matching function for call to `B::f ()'
| b.c:11: candidates are: void B::f(char)
| 
| I use gcc version 2.95.1 19990816 (release).
| 
| It seems that method A::f(void) can be found without any problems.

[ This is a C++ language issue, not GCC problem and is best handled on 
news:comp.lang.c++.moderated ]

verloading is when there is more than one declarations for the same
name in the *same scope*.  Names declared in base classes and names
declared in a derived class are not in the same scope. 

For your program to work as you intented, you need to tell C++ you do
want to overload (as opposed to hide) by bringing A::f in scope: 

	class B : public A {
	public:
		using A::f;
		void f(char);
	};

Hope this helps,

-- Gaby
	



More information about the Gcc-bugs mailing list