C++ question

This is a discussion on C++ question within the C++ Programming forums, part of the General Programming Boards category; All member functions that are pure virtual can have a definition, plain and simple. From another source: ... It is ...

  1. #46
    CS Author and Instructor
    Join Date
    Sep 2002
    Posts
    511

    Talking

    All member functions that are pure virtual can have a definition, plain and simple.
    From another source:



    ... It is the = 0 in the prototype that makes a virtual function a pure virtual function. In this case the function had no definition, but C++ does not allow even a pure virtual function to have a definition.
    Mr. C: Author and Instructor

  2. #47
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    And I once again will tell you that a pure virtual function, as defined by the standard can have a definition. If you read otherwise then it is just ignorant people who either don't know the stardard or who try to simplify what pure virtual functions are for means of teaching.

  3. #48
    Registered User
    Join Date
    Sep 2002
    Posts
    272
    Polymorphic OOP is correct; it's another Stroustrop boo-boo. The member can be declared as abstract and be called from within the base class.
    Joe

  4. #49
    Registered User datainjector's Avatar
    Join Date
    Mar 2002
    Posts
    356
    I need some questions
    "I wish i could wish my wishs away"

    "By indirections find directions out" -- William Shakespears

    "Do what thou wilt shall be the whole of the law" -- Crowley "THE BEAST 666"

    Mizra -> love = Death...
    RDB(Rocks yooo)..

    http://www.cbeginnersunited.com

    Are you ready for the Trix ???

  5. #50
    moi
    moi is offline
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    Originally posted by JoeSixpack
    Also, beware of quoting Stroustrup. Taken from one of the early chapter is his 3rd edition -
    that is 100% correct.
    hello, internet!

  6. #51
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    This whole thread boils down to one single line that most of you are ignoring:
    C. a pure virtual function cannot have an implementation.
    This is a simple true/false scenario. Can it have an implementation? I believe it has been proven that, yes in fact it can. As such, that is wrong. It's basic C++ here people. It's either true or it's false. It can't be both. It's yes or no.

    To quote a few points of reference:

    A PDF file on the topic in question...
    The derived classes may define an
    implementation for the virtual function.
    If the derived class does not include an implementation for the pure virtual function, the derived class is an abstract class.
    Emphesis mine. Note the big if there. It doesn't say that it cannot have one, it says in fact the opposite. If it does (not). This would imply that it's possible.

    Again...
    Code:
    A pure virtual function may have an implimentation.   For example
    
    class Abstract
    {
       virtual void Output() = 0
       {
             cout << "Nothing to do";
       }
    };
    
    is completely legal--and not that uncommon.
    I'll stop there because it's becomming painfully obvious that C is incorrect, even with my limited knowledge of C++. It's amazing what you can do with a serach engine.

    Quzah.
    Hope is the first step on the road to disappointment.

  7. #52
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    Sorry but polymorphic is right.

    Any pure virtual function may have an implementation. Its the =0 syntax that makes it pure not the prescence or abscence of an implementation.

    Here is a link to a small article by herb sutter on (im)pure virtual functions.
    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

  8. #53
    Registered User
    Join Date
    Sep 2002
    Posts
    272
    quzah:

    I agree but your pdf example has bugger all to do with the point (you are taking it out of context).

    Instead of dancing round the point. For those that give a **** -

    2 An abstract class is a class that can be used only as a base class of some other class; no objects of an
    abstract class can be created except as subobjects
    of a class derived from it. A class is abstract if it has at
    least one pure virtual function. [Note: such a function might be inherited: see below. ] A virtual function is
    specified pure by using a purespecifier
    (9.2) in the function declaration in the class declaration. A pure
    virtual function need be defined only if explicitly called with the qualifiedid
    syntax (5.1).
    which comes from the standard; minus the example.
    Joe

  9. #54
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Originally posted by JoeSixpack
    quzah:

    I agree but your pdf example has bugger all to do with the point (you are taking it out of context).
    You're right. I misread it. Fortunately for me, the point still stands. It's also nice to have additional references, such as yours, especially since it's the standard you're quoting.

    Quzah.
    Hope is the first step on the road to disappointment.

  10. #55
    CS Author and Instructor
    Join Date
    Sep 2002
    Posts
    511

    Wink

    Fine, here are some more question found out of the D & D text:

    Code:
    10.3 Select the false statement. virtual functions
    (a) allow the program to select the correct implementation at execution time.
    (b) can use both static or dynamic binding, depending on the handles of which the functions
    are called.
    (c) cannot have their references resolved at compile time.
    (d) can be called using the dot operator.
    
    
    10.6 Abstract classes
    (a) must explicitly include a pure virtual function.
    (b) can have objects instantiated from them if the proper permissions are set.
    (c) cannot have abstract derived classes.
    (d) are defined, but the programmer never intents to instantiate any objects them.
    
    10.11 Which of the following are not allowed?
    (a) Objects of abstract classes.
    (b) Multiple pure virtual functions in abstract classes.
    (c) References to abstract classes.
    (d) Arrays of pointers to abstract classes.
    
    8.6 In order to overload the += operator
    (a) only the + operator needs to be overloaded.
    (b) only the + and = operators need to be overloaded.
    (c) the += operator must be explicitly overloaded.
    (d) the + and = operators need to be overloaded implicitly.
    
    8.11 Suppose the unary ! operator is an overloaded member function of class String.
    For a String object s,which function call is generated by the compiler when it finds the
    expression !s?
    (a) s.operator!()
    (b) s.operator!(default value1, default value2...)
    (c) s->!
    (d) a compiler error results because no arguments are given
    As for the pure virtual function question: go to www.deitel.com an tell them- about that question. They do answer back.
    Mr. C: Author and Instructor

  11. #56
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Originally posted by Mister C
    Fine, here are some more question found out of the D & D text:
    What does all this crap have to do with Dungeons & Dragons?

    Quzah.
    Hope is the first step on the road to disappointment.

  12. #57
    moi
    moi is offline
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    Originally posted by Mister C
    Fine, here are some more question found out of the D & D text:
    ...
    just because a book has it one way means nothing.
    hello, internet!

  13. #58
    CS Author and Instructor
    Join Date
    Sep 2002
    Posts
    511

    Unhappy

    Sorry, it is the Deitel & Deitel : C++ How to Program text. I did not know that D & D stands for "dungeons and dragons". Is that a role playing game?
    Mr. C: Author and Instructor

  14. #59
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Originally posted by Mister C
    Sorry, it is the Deitel & Deitel : C++ How to Program text. I did not know that D & D stands for "dungeons and dragons". Is that a role playing game?
    Hehe. I knew what you were referring to. But yes, "D&D" is the role playing game that started pretty much all role playing games. (No, this isn't entirely correct, but in reality, it's the one that put RPGs on the map.)

    Basicly, D&D is pretty much the father of all role playing games. Let's not debate the issue here, (speaking in general to the masses that may read this) basicly it's the largest commercial "pen and paper" RPG system.

    They have a slew of computer games, but their origins are pen and paper games. They were bought by Wizards of the Coast.

    Anyway, it (my original D&D reply) was just meant as a joke.

    Quzah.
    Hope is the first step on the road to disappointment.

  15. #60
    CS Author and Instructor
    Join Date
    Sep 2002
    Posts
    511

    Wink

    THanks, we teachers are older people. I did not play role playing games. We played alot of RISK and Castle RISK and Monopoly.

    Anyway, bad questions. I need to look at them closer.
    Mr. C: Author and Instructor

Page 4 of 4 FirstFirst 1234
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 03:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 06:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 01:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 10:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM

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