C
Christian Christmann
Hi,
I'm reading "C++ Coding Standards" by Herb Sutter.
On page 67 there's an example which I don't understand:
---------------------------------
class Base{// ...
virtual void Foo(int);
virtual void Foo(int, int);
void Foo(int, int, int);
};
class Derived : public Base { // ...
virtual void Foo(int); // overrides Base::Foo(int), but hides the others
};
Derived d;
d.Foo(1); // ok
d.Foo(1,2); // error
d.Foo(1,2,3); // error
-----------------------------------
I don't understand why the functions "virtual void Foo(int, int)" and
"void Foo(int, int, int)" are hidden by Derived::Foo(int) ?
My opinion was that a derived class is always inheriting all functions
of a base class and can additionally override them for a specific purpose
like Foo(int).
To bring the other Base::Foo overloads into scope Sutter is using the
statement
using Base::Foo;
within the Derive class.
Thank you for your answers.
Greeting,
Chris
I'm reading "C++ Coding Standards" by Herb Sutter.
On page 67 there's an example which I don't understand:
---------------------------------
class Base{// ...
virtual void Foo(int);
virtual void Foo(int, int);
void Foo(int, int, int);
};
class Derived : public Base { // ...
virtual void Foo(int); // overrides Base::Foo(int), but hides the others
};
Derived d;
d.Foo(1); // ok
d.Foo(1,2); // error
d.Foo(1,2,3); // error
-----------------------------------
I don't understand why the functions "virtual void Foo(int, int)" and
"void Foo(int, int, int)" are hidden by Derived::Foo(int) ?
My opinion was that a derived class is always inheriting all functions
of a base class and can additionally override them for a specific purpose
like Foo(int).
To bring the other Base::Foo overloads into scope Sutter is using the
statement
using Base::Foo;
within the Derive class.
Thank you for your answers.
Greeting,
Chris