Thread: Question about redefining functions in derived class

  1. #1
    Registered User Sharke's Avatar
    Join Date
    Jun 2008
    Location
    NYC
    Posts
    303

    Question about redefining functions in derived class

    Back to the hard slog of learning C++ after a longish break. Unfortunately it seems I've forgotten some in the meantime! Bruce Eckel's "Thinking in C++," chapter 14, question 15:

    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.
    So I have:

    Code:
    class Base 
    {
    public:
        static void f1() {cout << "static void f1()\n";}
        static void f2() {cout << "static void f2()\n";}
    };
    
    class Derived : public Base
    {
    public:
        static void f1() {cout << "Derived static void f1()\n";}
    };
    Am I correct in my understanding of "redefine" that the derived f1() redefines the base f1()? If so, what does the question mean that the other function is now "hidden"? Because it appears I can call both without error:

    Code:
    Derived::f1();
    Derived::f2();

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    I think that the question is missing the word overloaded. Try doing it again, but this time as:
    Create a class with two overloaded static member functions. Inherit from this class and redefine one of the member functions. Show that the other is hidden in the derived class.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User Sharke's Avatar
    Join Date
    Jun 2008
    Location
    NYC
    Posts
    303
    That makes sense. The other function is now indeed hidden in the derived class.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help to build network class
    By weeb0 in forum C++ Programming
    Replies: 0
    Last Post: 02-01-2006, 11:33 AM
  2. simple question
    By SuperNewbie in forum C++ Programming
    Replies: 2
    Last Post: 01-24-2005, 03:03 PM
  3. Experienced coders read. ( Common/efficient writing )
    By knave in forum C++ Programming
    Replies: 8
    Last Post: 04-23-2003, 09:07 PM
  4. question about DLL's and class functions
    By btq in forum Windows Programming
    Replies: 2
    Last Post: 02-25-2003, 06:08 AM
  5. Troubles overriding a const in a derived class
    By sh0x in forum C++ Programming
    Replies: 5
    Last Post: 10-05-2001, 07:11 PM