ATL_NO_VTABLE可以让编译器不产生VTable,并且不设置VPointer的值。
正常情况下,在调用构造函数和析构函数的时候,编译器都会插入相应的代码。如果ATL_NO_VTABLE,可以省去这些代码。ATL中使用这个,是因为这个类为抽象类,不需要VTable。真正的类是CComObject<XXX>,它继承用户的类。


--------------------------------------------------------------

#define ATL_NO_VTABLE __declspec(novtable)

class ATL_NO_VTABLE MyBase
{
public:
	MyBase()
	{
		cout << "MyBase::MyBase()" << endl;
	}
	virtual ~MyBase()
	{
		cout << "MyBase::~MyBase()" << endl;
	}
};
class Derive :public MyBase
{
public:
	Derive()
	{
		cout << "Derive::Derive()" << endl;
	}
	virtual ~Derive()
	{
		cout << "Derive::~Derive()" << endl;
	}
};


int main(int argc, char* argv[])
{

	MyBase* p1 = new Derive;
	delete p1;

	cout << "==========================" << endl;
	
	MyBase* p2 = new MyBase();
	delete p2;//运行时出错

	return 0;
}


--------------------------------------------------------------

相关文章:

  • 2022-02-17
  • 2021-07-12
  • 2021-08-09
  • 2022-12-23
  • 2021-09-05
  • 2022-02-26
  • 2022-12-23
  • 2021-12-03
猜你喜欢
  • 2021-11-08
  • 2021-12-02
  • 2022-12-23
  • 2021-06-05
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案