您的位置:首页 > 其它

ATL窗口继承实现机制

2005-12-20 16:38 246 查看
学习WTL时,发现其窗口实现模式采用ATL窗口实现方式,于是对ATL窗口实现机制研究一下。其主要思想还是继承和模板,避免需函数导致运行时类结构增大。利用控制台程序模拟如下:#include <iostream>template<class T>
class A
{
public:
A()
{
}
virtual ~A()
{
}
void Say()
{
(static_cast<T*>(this))->Say();
}
};class DeriveA : public A<DeriveA>
{
public:
DeriveA() : A<DeriveA>()
{
}
void Say()
{
std::cout << "Hello, World!" << std::endl;
}
};int main(int argc, char* argv[])
{
DeriveA a;
a.Say();
return 0;
}主要通过基类的this指针识别对象。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: