Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Can virtual function be inline?

Reply
Thread Tools

Can virtual function be inline?

 
 
doublemaster007@gmail.com
Guest
Posts: n/a
 
      03-14-2009

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.
 
Reply With Quote
 
 
 
 
Chetan
Guest
Posts: n/a
 
      03-14-2009
"(E-Mail Removed)" <(E-Mail Removed)> 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.
 
Reply With Quote
 
 
 
 
James Kanze
Guest
Posts: n/a
 
      03-14-2009
On Mar 14, 8:31 am, "(E-Mail Removed)"
<(E-Mail Removed)> 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:(E-Mail Removed)
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
virtual vs pure virtual member function sam_cit@yahoo.co.in C++ 7 05-02-2007 10:00 AM
same overhead in calling virtual and non virtual member function...? ypjofficial@indiatimes.com C++ 11 09-10-2006 06:08 PM
virtual inheritance and virtual function. Ashwin C++ 2 08-01-2006 12:48 PM
virtual function and pure virtual function in the implementation of COM IK C++ 2 07-23-2004 02:55 PM
What will happen if a virtual function is declared to be virtual again in a derived class? Xiangliang Meng C++ 2 06-21-2004 03:14 AM



Advertisments