C++ virtual function table memory cost

前端 未结 13 1766
抹茶落季
抹茶落季 2020-12-03 08:14

Consider:

class A
{
    public:
        virtual void update() = 0;
}

class B : public A
{
    public:
        void update() { /* stuff goes in here... */ }
         


        
13条回答
  •  借酒劲吻你
    2020-12-03 09:03

    The space cost of a vtable is one pointer (modulo alignment). The table itself is not placed into each instance of the class.

提交回复
热议问题