开发者

what will happen to inline functions inside virtual functions?

开发者 https://www.devze.com 2022-12-21 06:26 出处:网络
What will happen if I use a inline function inside a virtual function? I\'m confused with questions like

What will happen if I use a inline function inside a virtual function? I'm confused with questions like http://www.parashift.com/c++-faq-lite/value-vs-ref-semantics.html#faq-31.6

I can understand it, but is that mean, it will non-sense to use (cal开发者_如何学Cl) inline functions inside virtual functions (please assume that it is calling dynamically)?

class Wrapper
{
public:
   inline void doInlineJob() {;}
};

class Base
{
   virtual void foo()
   {
     //Do something
   }
};

class Derived: public Base
{
    void foo()
    {
      wrapObj.doInlineJob();
    }

    Wrapper wrapObj;
};


It doesn't matter whether foo is virtual or not. It only matters whether doInlineJob is virtual. It's not, so it can be inlined without a problem.


What will happen if I use a inline function inside a virtual function?

Nothing special. If the compiler agrees, it will be inlined, if not, it won't. Just like from any other function.

(Note that the FAQ talks about functions which are themselves inline and virtual at the same time. That's different.)

0

精彩评论

暂无评论...
验证码 换一张
取 消