efficiency of calling one virtual member of class from another

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I have a base class and several subclasses.  They have several virtual
member functions.

class Base {
    ...
     virtual void *f(int a) = 0;
     virtual void *g(int a) = 0;
}

class Sub1 : Base {
    ...
     void *f(int a) {
         code_f;
         return something;
     }

     void *g(int a) {
         code_g1;
         void *r = f(a+1);     // question here
         code_g2;
         return r;
    }
}

class Sub2 : Base {
   similar...
}

I have not and do not intend to define any subclasses of Sub1 or the
other subclasses at this level.  Base and all the subclasses are in the
same .h file.

The question is, what happens when I call f() from g()?  At -O3?  Does
it go though the usual vector dispatch table, does it call code for the
same instance of f directly, does it inline f in g (separately for each
subclass), or something else?  Why?  And, has it recently or is it going
to change?

Is there a reference I should have read rather than asking this question?

Thanks, Bill





[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux