"exits funnel" <ex*********@NOSPAMyahoo.com> wrote...
One of the problems at the end of Chapter 14 in Bruce Eckel's thinking
in C++ reads as follows:
Create a class with two static member functions. Inherit from this
class and redefine one of the member functions. Show that the other is
hidden in the derived class.
The simple test code I wrote seems NOT to confirm this. The question
then: Is Eckel right or is my compiler right? I'm guessing the
compiler since the behavior he seems to imply makes no sense whatsoever.
I think the exercise depends on the definition of "other". Bruce's
"Name Hiding" part of chapter 14 gives an example of class Base with
_two_ functions named "f". Perhaps he wants you to have to functions
with the same name in your base class... I suppose the text of the
exercise ought to read "Create a class with two OVERLOADED member
functions. [...]"
Anyway...
Two examples:
// One -- probably your result
struct A {
static void foo(int);
static void bar(double);
};
struct B : A {
static void foo(int);
};
int main() {
B::bar(3.14159); // OK, the "other", A::bar(double)
// is NOT hidden by B::foo(int)
}
// Two
struct A {
static void foo(int);
static void foo(double); // overloaded
};
struct B : A {
static void foo(int);
};
int main() {
B::foo(3.14159); // cannot do, the "other", A::foo(double)
// is _also_ hidden by B::foo()
}
Check out the part "Inheritance and static member functions" in the same
chapter. Items #2 and #3 in the list are of interest.
Good luck! From what I've seen Bruce Eckel's books are OK, but not free
of quirks. Find your way through them, and you're going to come out
a better C++ programmer than if you worked through a book without quirks.
Victor