Topic: Inheritance/overloading problem
Author: "Dean Wakerley" <dean@housefloors.co.uk>
Date: Wed, 5 Sep 2001 16:46:40 GMT Raw View
Apologies for typo, middle_c should publicly inherit base_c and top_c should
publicly inherit middle_c.
See corrected post.
Dean
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
Author: "Dean Wakerley" <dean@housefloors.co.uk>
Date: Tue, 4 Sep 2001 15:24:35 GMT Raw View
I'm getting this error message when compiling the following code.
test.cc: In function `int main()':
test.cc:31: no matching function for call to `top_c::func (char)'
test.cc:20: candidates are: void top_c::func()
// ----- start of code ---------
#include <iostream>
class base_c
{
public:
virtual void func()=0;
virtual void func(char)=0;
};
class middle_c
{
public:
void func() { cout << "middle_c::func()" << endl; };
void func(char) { cout << "middle_c::func(char)" << endl; };
};
class top_c
{
public:
void func() { cout << "top_c::func()" << endl; };
/* void func(char);
* use function inherited from middle_c
*/
};
int
main(/*...*/)
{
top_c t;
t.func(); // works
t.func('x'); // problem: no matching function???
return 0;
}
// ----- end of code ---------
Is this a language problem or a compiler problem?, and how do I get around
it?
TIA,
Dean
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
Author: Ron Natalie <ron@sensor.com>
Date: Tue, 4 Sep 2001 17:51:15 GMT Raw View
> class top_c
> {
> public:
> void func() { cout << "top_c::func()" << endl; };
> /* void func(char);
> * use function inherited from middle_c
> */
> };
>
The above comment is wrong. Members are looked up by NAME (not
signature) then when the name is located, possible overloads are
examined. func in the scope of top_c evaluates to top_c::func
which there is exactly one overload.
If you want to bring forward the middle_c definitions, you need
to do:
class top_c {
public:
using middle_c::func; // bring through middle_c func
void func() { /* ... */ } // add an overload for no arg case
};
This is in the FAQ (you might find it better to start there).
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
Author: "Marcin 'Qrczak' Kowalczyk" <qrczak@knm.org.pl>
Date: Tue, 4 Sep 2001 22:10:15 GMT Raw View
Tue, 4 Sep 2001 15:24:35 GMT, Dean Wakerley <dean@housefloors.co.uk> pis=
ze:
> class top_c
> {
> public:
> void func() { cout << "top_c::func()" << endl; };
> /* void func(char);
> * use function inherited from middle_c
> */
It doesn't inherit from middle_c.
--=20
__("< Marcin Kowalczyk * qrczak@knm.org.pl http://qrczak.ids.net.pl/
\__/
^^ SYGNATURA ZAST=CAPCZA
QRCZAK
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]