Thread: derived class

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    1,579

    derived class

    Hello everyone,


    What does the following statement about derived class mean?

    http://www.gotw.ca/gotw/059.htm

    --------------------
    Unreasonable Statement #1: "Polymorphism doesn't work in C++ because you can't make an arbitrary class usable in place of a Base& without changing it (to derive from Base)."
    --------------------


    thanks in advance,
    George

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    It means that object oriented polymorphism in C++ needs inheritance, so if you disallow changes to use inheritance, it is unreasonable to state that polymorphism does not work in C++.
    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
    Join Date
    May 2006
    Posts
    1,579
    Thanks laserlight,


    What means "disallow changes"? For example?

    Quote Originally Posted by laserlight View Post
    It means that object oriented polymorphism in C++ needs inheritance, so if you disallow changes to use inheritance, it is unreasonable to state that polymorphism does not work in C++.

    regards,
    George

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    What means "disallow changes"? For example?
    You are not allowed to edit any of the code related to the class. Yes, close your text editor or IDE right now.
    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

  5. #5
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Hi laserlight,


    Why do I need to modify the base class if I want to write a derived class?

    Quote Originally Posted by laserlight View Post
    You are not allowed to edit any of the code related to the class. Yes, close your text editor or IDE right now.

    regards,
    George

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Why do I need to modify the base class if I want to write a derived class?
    You need to modify the arbitrary class to make it a 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

  7. #7
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Thanks laserlight,


    Question answered.

    Quote Originally Posted by laserlight View Post
    You need to modify the arbitrary class to make it a derived class.

    regards,
    George

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. call base class function or derived class function
    By George2 in forum C++ Programming
    Replies: 4
    Last Post: 03-18-2008, 05:23 AM
  2. Two conceptual questions
    By AntiScience in forum C++ Programming
    Replies: 3
    Last Post: 11-01-2007, 11:36 AM
  3. derived class can not access base class protected member?
    By George2 in forum C++ Programming
    Replies: 2
    Last Post: 10-21-2007, 06:32 PM
  4. Replies: 4
    Last Post: 12-29-2002, 12:29 AM
  5. Constructors + Derived class
    By MethodMan in forum C++ Programming
    Replies: 6
    Last Post: 11-10-2002, 05:05 PM