Can virtual function be inline?

D

doublemaster007

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

Chetan

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

James Kanze

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top