"interface"

Discussion in 'C++' started by seesaw, Apr 29, 2004.

  1. seesaw

    seesaw Guest

    When define an interface of all pure virtual functions, will the destructor
    of it will automatically virtual, or it has to be declared as virtual?
    Should it be declared as "virtual" when defining the interface?
     
    seesaw, Apr 29, 2004
    #1
    1. Advertising

  2. seesaw

    Phlip Guest

    seesaw wrote:

    > When define an interface of all pure virtual functions, will the

    destructor
    > of it will automatically virtual, or it has to be declared as virtual?
    > Should it be declared as "virtual" when defining the interface?


    In C++, you don't pay for what you don't use.

    Suppose, someday many winters from now, you wrote a program, and then
    profiled it, and discovered the only way to make it faster was to take out a
    single virtual destructor.

    If the C++ committees had decreed that undeclared destructors of purely
    abstract base classes were magically virtual, you would be screwed.

    So, until that day, get in the habit of writing...

    virtual ~myClass() = 0;

    ....to make destructors pure virtual, too.

    (If the abstract class weren't pure - if it had a member that needs
    destruction, the = 0 won't prevent this.)

    --
    Phlip
    http://www.xpsd.org/cgi-bin/wiki?TestFirstUserInterfaces
     
    Phlip, Apr 29, 2004
    #2
    1. Advertising

  3. seesaw

    John Carson Guest

    "seesaw" <> wrote in message
    news:eek:I%jc.33906$
    > When define an interface of all pure virtual functions, will the
    > destructor of it will automatically virtual, or it has to be declared
    > as virtual? Should it be declared as "virtual" when defining the
    > interface?


    It has to be declared virtual.


    --
    John Carson
    1. To reply to email address, remove donald
    2. Don't reply to email address (post here instead)
     
    John Carson, Apr 29, 2004
    #3
    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. Wildepiet
    Replies:
    0
    Views:
    1,887
    Wildepiet
    Jun 14, 2004
  2. cyberco
    Replies:
    8
    Views:
    511
    cyberco
    Feb 25, 2006
  3. Xah Lee
    Replies:
    15
    Views:
    614
    Sherm Pendley
    Mar 23, 2007
  4. Xah Lee
    Replies:
    15
    Views:
    645
    Sherm Pendley
    Mar 23, 2007
  5. Replies:
    4
    Views:
    361
    timjowers
    Nov 2, 2007
Loading...

Share This Page