Question about redefining functions in derived class

This is a discussion on Question about redefining functions in derived class within the C++ Programming forums, part of the General Programming Boards category; Back to the hard slog of learning C++ after a longish break. Unfortunately it seems I've forgotten some in the ...

  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
    21,717
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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, 10:33 AM
  2. simple question
    By SuperNewbie in forum C++ Programming
    Replies: 2
    Last Post: 01-24-2005, 02: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, 05: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21