"interface"

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • seesaw

    "interface"

    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?


  • Phlip

    #2
    Re: "interface "

    seesaw wrote:
    [color=blue]
    > When define an interface of all pure virtual functions, will the[/color]
    destructor[color=blue]
    > of it will automatically virtual, or it has to be declared as virtual?
    > Should it be declared as "virtual" when defining the interface?[/color]

    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





    Comment

    • John Carson

      #3
      Re: "interface "

      "seesaw" <seesaw@turbowe b.com> wrote in message
      news:oI%jc.3390 6$_o3.1100044@b gtnsc05-news.ops.worldn et.att.net[color=blue]
      > 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?[/color]

      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)

      Comment

      Working...