不为类、对象的函数分配空间;
在类中如果有virtual声明的虚函数,则会隐藏一个指针,该指针指向虚函数表,这对于纯虚函数也是一样;
对于虚继承,还有一个指向父类的指针,该指针为指向虚基类的指针(Pointer to virtual base class)。
#include "stdafx.h"#includeusing namespace std;#include "t1.h"class TNULL{};class Ti{ int i;};class Tic{ int i; char c;};class Tf{ void f(void){}};class T_vf{ virtual void f(void){}};class Tif {public: void set(int x) {i = x;}private: int i;};class Ti_vf {public: virtual void set(int x) {i = x;}private: int i;};class Ti_v0f {public: virtual void set(int x) = 0;private: int i;};class Ti_sf { int i; static void sf(void){}};class TT{ TT(){}};class TxT{ ~TxT(){}};class TTT{ TTT(){} ~TTT(){}private: Tif* m_pTif;};class TTTFFF{public: TTTFFF() { m_pTif = new Tif; m_pTif->set(0); } ~TTTFFF(){ delete(m_pTif); m_pTif = 0; } void f1(void){} void f2(void){} void f3(void){}private: Tif* m_pTif;};class TTT_VFFF{public: TTT_VFFF() { m_pTif = new Tif; m_pTif->set(0); } ~TTT_VFFF(){ delete(m_pTif); m_pTif = 0; } virtual void f1(void){} virtual void f2(void){} virtual void f3(void){}private: Tif* m_pTif;};void t1(void){ cout<<"sizeof(char) = "< <
扩展:
1. http://www.cnblogs.com/luxiaoxun/archive/2012/09/01/2666395.html
2. http://blog.csdn.net/haoel/article/details/1948051