一个古怪的编译问题 - WTL 看准了是WTL

UnrealImagecoffee UnrealImagecoffee 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我怎么没法子让程序编译通过 - 我已经安装了WTL

#include <iostream.h>

template <class T>
class B1
{
public:
void SayHi()
{
T* pT = static_cast<T*>(this);
pT->PrintClassName();
}
protected:
void PrintClassName()
{
cout << "This is B1 class";
}
};

class D1 : public B1<D1>
{
// No overridden function at all
};

class D2 : public B1<D2>
{
protected:
void PrintClassName()
{
cout << "This is D2 class";
}
};

int main(int argc, char *argv[])
{
D1 d1;
D2 d2;

d1.SayHi(); // prints "This is B1"
d2.SayHi(); // prints "This is D2"

return 0;
}
...全文
评论 2
收藏 已收藏
分享
返回顶部
UnrealImagecoffee
VC/MFC 16,550 成员 421,606 内容