pure virtual function: implementation?

Discussion in 'C++' started by al.cpwn@gmail.com, Mar 19, 2006.

  1. Guest

    This is OT but since this is the c++ hangout someone might know how
    this is implemented in c++ compilers. What happens when you declare a
    function pure virtual in the vptr/vtable system: does the "= 0" mean
    that the function pointer itself is set to 0?
    , Mar 19, 2006
    #1
    1. Advertising

  2. Axter Guest

    wrote:
    > This is OT but since this is the c++ hangout someone might know how
    > this is implemented in c++ compilers. What happens when you declare a
    > function pure virtual in the vptr/vtable system: does the "= 0" mean
    > that the function pointer itself is set to 0?


    It shouldn't mean that, since you can declare implementation for a pure
    virtual function on the base class itself.

    class Base
    {
    public:
    virtual int MyVirtFunct()=0
    {
    return 0; //Pure virtual function implementation on base class
    }
    };
    Axter, Mar 19, 2006
    #2
    1. Advertising

  3. Kiuhnm Guest

    ha scritto:
    > This is OT but since this is the c++ hangout someone might know how
    > this is implemented in c++ compilers. What happens when you declare a
    > function pure virtual in the vptr/vtable system: does the "= 0" mean
    > that the function pointer itself is set to 0?


    You cannot instantiate an abstract class then that pointer cannot be null.

    Kiuhnm
    Kiuhnm, Mar 19, 2006
    #3
  4. AnalogFile Guest

    wrote:
    > This is OT but since this is the c++ hangout someone might know how
    > this is implemented in c++ compilers. What happens when you declare a
    > function pure virtual in the vptr/vtable system: does the "= 0" mean
    > that the function pointer itself is set to 0?


    If you provide an implementation for the function, it points to that.
    If you do not, it points to whatever the compiler author decided to
    point it at (formally: implementation defined).

    A common compiler behavior is to point to an internal function that
    prints a diagnostic and aborts execution.

    It is not very interesting as you cannot instantiate an abstract class
    anyway.

    And formally ... vptr/vtable is not mandatory. If you can figure out a
    different mechanism it's ok.
    AnalogFile, Mar 19, 2006
    #4
    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:
    590
    hemraj
    Jul 23, 2004
  2. Todd Aspeotis
    Replies:
    3
    Views:
    449
    Kanenas
    May 30, 2005
  3. John Goche
    Replies:
    10
    Views:
    720
    Marcus Kwok
    Dec 8, 2006
  4. Replies:
    7
    Views:
    574
    James Kanze
    May 2, 2007
  5. a
    Replies:
    7
    Views:
    353
    dasjotre
    Jun 28, 2007
Loading...

Share This Page