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. Advertisements

  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. Advertisements

  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. Advertisements

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. Xiangliang Meng
    Replies:
    2
    Views:
    516
    Jack Klein
    Jun 21, 2004
  2. IK
    Replies:
    2
    Views:
    789
    hemraj
    Jul 23, 2004
  3. puzzlecracker

    virtual function, inline, diamond?

    puzzlecracker, Jan 14, 2005, in forum: C++
    Replies:
    3
    Views:
    380
    Alf P. Steinbach
    Jan 14, 2005
  4. Nish
    Replies:
    4
    Views:
    750
    Thomas Stegen
    Oct 8, 2004
  5. TGOS
    Replies:
    3
    Views:
    560
    Kevin Bracey
    Feb 28, 2005
  6. Ajay
    Replies:
    5
    Views:
    629
    Pete Becker
    Apr 1, 2006
  7. Replies:
    7
    Views:
    667
  8. shuisheng
    Replies:
    3
    Views:
    330
    Kevin Handy
    Oct 3, 2006
Loading...