Can virtual function be inline?

Discussion in 'C++' started by doublemaster007@gmail.com, Mar 14, 2009.

  1. Guest

    Can virtual function be inline? if so how can compiler copy the code
    during the compile time itself? since virtual function call is
    determined @ run time.
     
    , Mar 14, 2009
    #1
    1. Advertising

  2. Chetan Guest

    "" <> writes:

    > Can virtual function be inline? if so how can compiler copy the code
    > during the compile time itself? since virtual function call is
    > determined @ run time.


    Yes it can. However the compiler can inline it only when it knows for
    sure which function is to be called. Most other cases it is called as
    a virtual function.
     
    Chetan, Mar 14, 2009
    #2
    1. Advertising

  3. James Kanze Guest

    On Mar 14, 8:31 am, ""
    <> wrote:
    > Can virtual function be inline? if so how can compiler copy
    > the code during the compile time itself? since virtual
    > function call is determined @ run time.


    A virtual function call results in the function being determined
    by the dynamic type of the object. Most compilers will inline a
    virtual function if they know the dynamic type of the object.
    Some (very few) will also use profiling information: if the call
    is in a critical loop, and the actual function called is almost
    always the same, they'll generate an if on that type, inlining
    the special, most frequent case, and using the usual virtual
    call method otherwise.

    --
    James Kanze (GABI Software) email:
    Conseils en informatique orientée objet/
    Beratung in objektorientierter Datenverarbeitung
    9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
     
    James Kanze, Mar 14, 2009
    #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. IK
    Replies:
    2
    Views:
    617
    hemraj
    Jul 23, 2004
  2. Nish
    Replies:
    4
    Views:
    496
    Thomas Stegen
    Oct 8, 2004
  3. TGOS
    Replies:
    3
    Views:
    381
    Kevin Bracey
    Feb 28, 2005
  4. Ajay
    Replies:
    5
    Views:
    395
    Pete Becker
    Apr 1, 2006
  5. Replies:
    7
    Views:
    449
Loading...

Share This Page