A few people have been asking about variants of this recently, and I'm
still not totally clear.
A class Base declares, amongst other things, a method called func().
Because derived classes might replace this with their own
implementation, func is declared as virtual in Base:
// header
class Base
{
public:
virtual int func(int arg1);
}
Because not all derived classes will wish to provide their own
implementation, Base provides a default one:
int
Base::func(int arg1)
{
......
}
This particular derived class in fact does not replace func():
class Derived : public Base
{
......
}
In the application code, I create a Derived object, and then call the
func() method:
{
Derived x;
int i = x.func(12345);
}
So, by my understanding, this is all fine, and indeed, testing it
works fine; the Base::func() is called exactly as I would expect, and
all is exactly as written in the FAQ-Lite Q20.6[1]. And If Derived
does declare a replacement with the same signature, then again, it all
works as expected, and the Derived version is called. But as soon as
Derived declares a func() member of its own, but with a totally
different signature, the Base version is hidden, and we have to have a
'using' clause in Derived to make it visible again. This is where I'm
stuck; surely, it should look up by the signature, then find
Base::func(int) through the vtable? Why does the damned thing get
hidden?
1.
http://www.ensta.fr/~diam/c++/online....html#faq-20.6
--
PGP key ID 0xEB7180EC