Thread: Why did I get this question wrong?

  1. #1
    Still A Registered User DISGUISED's Avatar
    Join Date
    Aug 2001
    Posts
    499

    Why did I get this question wrong?

    ok. First of all, there can be only one anwser to this question. The quesiton is.

    Question from my test.

    The reason for declaring a pure virtual function is:

    A. The function will always exsist in each of the derived classes.

    B. Each copy of the function is completely different in each of the derived classes.

    C. There is no common denominator between versions of the function in the derived classes.

    D. All of the above.

    E. None of the above.

    The anwser was D. I said B. I missed this because I was confused about A.

    Is it true, that if you don't overide the pure virtual function in a derived class, this class will just become abstract itself? Then you could derive other classes from this abstract and maybe enhance it with other pure virtual functions? Maybe I am wrong but I would like to argue this one because it cost me an A on the test.
    Last edited by DISGUISED; 01-30-2002 at 07:27 PM.

  2. #2
    Unregistered
    Guest
    I think B is wrong, but so is D. A is correct. C maybe I'm not interpreting correctly, but looks wrong.
    Any function you declare in a base class is inherited by all derived classes. A pure virtual function in a class makes that class abstract; you can't create instances or objects of that class, but you can derive classes for it. If you don't override the pure virtual function in a derived class, the derived class inherits the pure virtual function and is itself abstract.
    B could be true, but isn't necessarily true. C just seems wrong.

  3. #3
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    I also agree that the correct answer should have been A.
    B and C do not hold for all virtual functions.Sometimes those conditions are met and sometimes they are not.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  4. #4
    Registered User WebSnozz's Avatar
    Join Date
    Oct 2001
    Posts
    102
    What is a virtual function?
    WebSnozz-
    Cats have no butt cheeks.
    If one farted, then it would make a flute noise.

  5. #5
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >A. The function will always exsist in each of the derived classes.
    Yes

    >B. Each copy of the function is completely different in each of the derived classes.
    Sometimes, but not always

    >C. There is no common denominator between versions of the function in the derived classes.
    More or less, this could be worded better

    >D. All of the above.
    I can see how this would be the answer, but it's not wholely correct.

    A virtual function allows derived classes to replace the implementation provided by the base class. The compiler makes sure the replacement is always called whenever the object in question is actually of the derived class, even if the object is accessed by a base pointer rather than a derived pointer. This allows algorithms in the base class to be replaced in the derived class, even if users don't know about the derived class.

    The derived class can either fully replace ("override") the base class member function, or the derived class can partially replace ("augment") the base class member function. The latter is accomplished by having the derived class member function call the base class member function, if desired.

    -Prelude
    My best code is written with the delete key.

  6. #6
    Still A Registered User DISGUISED's Avatar
    Join Date
    Aug 2001
    Posts
    499

    Thanks

    >C. There is no common denominator between versions of the function in the derived classes.
    More or less, this could be worded better
    Man, you couldn't be more correct. This professor is a brilliant man and I could not learn this better from anybody else but he is from another country and let's just say his English skills when it comes to writing are not so great. He gets his point across most of the time but sometimes I don't even know what the question is asking.

    Like this question for example from a previous test.

    True or False: A distructor of a derived class should call the base class distructor as for the constructor function?

    I mean ..WHAT? I know it's false and I got it right because I had a 50/50 shot but I still do not know what this question means. And yes, that is how he spelled destructor on the test. And no, I don't think that was a trick question.

    Thanks for the help guys. I am just going to have to sit down with him and figure out exactly why he says "D". I am sure he has his reasons.

  7. #7
    Unregistered
    Guest
    I wouldn't push the issue too much, personally, but there is a common denominator in any set of overloaded funcitons whether they are plain, virtual, or pure virtual. The common denominator, that is, something which is common to all variations of the function:

    the function's name.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Design layer question
    By mdoland in forum C# Programming
    Replies: 0
    Last Post: 10-19-2007, 04:22 AM
  2. Newbish Question file reading question....
    By kas2002 in forum C Programming
    Replies: 23
    Last Post: 05-17-2007, 12:06 PM
  3. General forum question - if in wrong forum...
    By ulillillia in forum A Brief History of Cprogramming.com
    Replies: 28
    Last Post: 05-14-2007, 05:00 AM
  4. Very simple question, problem in my Code.
    By Vber in forum C Programming
    Replies: 7
    Last Post: 11-16-2002, 03:57 PM
  5. Math Question, hard
    By Yoshi in forum A Brief History of Cprogramming.com
    Replies: 34
    Last Post: 12-08-2001, 11:58 AM