C++: Virtual fnc Vs Pure fnc?

Discussion in 'C++' started by A, Nov 15, 2003.

  1. A

    A Guest

    Hi,

    1) Whats the difference from a virtual function and a pure virtual function?

    2) When would you use one over the over?

    3) What's the significance of the word virtual?


    Regards,
    A
     
    A, Nov 15, 2003
    #1
    1. Advertising

  2. A

    osmium Guest

    Re: Virtual fnc Vs Pure fnc?

    A wrote:

    > 1) Whats the difference from a virtual function and a pure virtual

    function?
    >
    > 2) When would you use one over the over?
    >
    > 3) What's the significance of the word virtual?


    That's a question I would normally try to answer, but it sounds just too
    much like a take-home test. Try google. If you answer 1 and 2 the answer
    to 3 should almost be a side effect.
     
    osmium, Nov 15, 2003
    #2
    1. Advertising

  3. > 1) Whats the difference from a virtual function and a pure virtual function?

    Virtual functions that must be overriden by the inheriting class are pure
    virtual function.

    > 2) When would you use one over the over?


    Use virtual functions when the base class can provide a reasonable
    default handling for the method. Use pure virtual when the base class
    just defines the interface for the function and no default handling
    is applicable.

    > 3) What's the significance of the word virtual?


    What's in a name? Virtual is a misleading keyword for overridable

    Sandeep
    --
    http://www.EventHelix.com/EventStudio
    EventStudio 2.0 - Generate Sequence Diagrams and Use Case Diagrams in PDF
     
    EventHelix.com, Nov 15, 2003
    #3
  4. A

    Ron Natalie Guest

    "EventHelix.com" <> wrote in message news:...
    > > 1) Whats the difference from a virtual function and a pure virtual function?

    >
    > Virtual functions that must be overriden by the inheriting class are pure
    > virtual function.


    ....or the derived class remains abstract.
    >
    > > 2) When would you use one over the over?

    >
    > Use virtual functions when the base class can provide a reasonable
    > default handling for the method. Use pure virtual when the base class
    > just defines the interface for the function and no default handling
    > is applicable.


    Or when you wish to force the derived class to at least think about whether
    the base class default is appropriate. There's no requirement that the base
    class not implement a pure virtual.

    > > 3) What's the significance of the word virtual?

    > What's in a name? Virtual is a misleading keyword for overridable


    Virtual...by definition: in appearance but not in fact. While it appears
    you are calling the base class function, you are in fact calling the one from
    the derived class.
     
    Ron Natalie, Nov 15, 2003
    #4
  5. A

    Deming He Guest

    Re: Virtual fnc Vs Pure fnc?

    osmium <> wrote in message
    news:bp55vu$1kfnr8$-berlin.de...
    > A wrote:
    >
    > > 1) Whats the difference from a virtual function and a pure virtual

    > function?
    > >

    Also, for a virtual function you need an implementation as a place holder,
    but for pure virtual, you don't.
     
    Deming He, Nov 16, 2003
    #5
  6. A

    Mike Smith Guest

    EventHelix.com wrote:
    >
    > What's in a name? Virtual is a misleading keyword for overridable


    It's more than that. Non-virtual functions can be overridden, too. The
    difference is *polymorphism*.

    --
    Mike Smith
     
    Mike Smith, Nov 18, 2003
    #6
  7. A

    Ron Natalie Guest

    "Mike Smith" <> wrote in message news:...
    > EventHelix.com wrote:
    > >
    > > What's in a name? Virtual is a misleading keyword for overridable

    >
    > It's more than that. Non-virtual functions can be overridden, too. The
    > difference is *polymorphism*.


    Non-virtual functions are not overriden. The definition of override in C++
    is based on virtual functions (10.3/2):

    If a virtual member function vf is declared in a class Base and in a class Derived, derived directly or
    indirectly from Base, a member function vf with the same name and same parameter list as Base::vf is
    declared, then Derived::vf is also virtual (whether or not it is so declared) and it overrides Base::vf.
     
    Ron Natalie, Nov 18, 2003
    #7
  8. A

    jeffc Guest

    "Ron Natalie" <> wrote in message
    news:3fb660be$0$75702$...
    > There's no requirement that the base
    > class not implement a pure virtual.


    For some reason, this is not intuitive for the vast majority of programmers.
     
    jeffc, Nov 18, 2003
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. IK
    Replies:
    2
    Views:
    629
    hemraj
    Jul 23, 2004
  2. Todd Aspeotis
    Replies:
    3
    Views:
    490
    Kanenas
    May 30, 2005
  3. John Goche
    Replies:
    10
    Views:
    787
    Marcus Kwok
    Dec 8, 2006
  4. Replies:
    7
    Views:
    605
    James Kanze
    May 2, 2007
  5. a
    Replies:
    7
    Views:
    376
    dasjotre
    Jun 28, 2007
Loading...

Share This Page