Size of virtual pointer-C++

前端 未结 6 733
迷失自我
迷失自我 2020-12-19 12:51

What is the size of virtual pointer(VPTR) for a virtual table in C++? Also this is not a homework question...just a question that came to my mind while I was reading a C++ b

6条回答
  •  旧巷少年郎
    2020-12-19 13:09

    The pointers in the virtual function table are generally the same size as regular pointers in the system. Typically a virtual function table is calculated for every type, and each object instance will contain a pointer to its type's table, so instances of objects containing virtual functions will use sizeof(void *) bytes more per instance than ones that don't. Types deriving from multiple base types must be castable to any base type so may contain multiple pointers to the base types' virtual function tables as necessary. All of this is compiler dependent of course.

提交回复
热议问题