https://blog.csdn.net/weixin_30446613/article/details/96499365
https://blog.csdn.net/weixin_40683787/article/details/119957270
https://blog.csdn.net/weixin_34351321/article/details/91817793
https://blog.csdn.net/weixin_34351321/article/details/91817793
https://zhuanlan.zhihu.com/p/137879448
https://zhuanlan.zhihu.com/p/136258767
https://www.zhihu.com/question/404956402
C++中模板类的编译过程
https://blog.csdn.net/u011201045/article/details/38679417
T t; //语法不通过,继承类内存大小不确定
T t; //语法通过*
这部分代码验证,原理就解释得通了
#include <iostream>
template <typename T>
class Base
{
public:
T t; //语法不通过,继承类内存大小不确定
T* t; //语法通过
public:
void doSomething()
{
T& derived = static_cast<T&>(*this);
}
};
class Derived : public Base<Derived>
{
public:
void doSomething()
{
std::cout << " Derived class " << std::endl;
}
};
int main()
{
Derived der;
der.doSomething();
std::cout << "Hello World!\n";
}