c++ - 基类和模板

标签 c++

<分区>

我可以这样写代码吗(试过了,在 VS2015 中无法编译):

template<class BaseClassT>
class DerivedClass : public BaseClassT
{
...
};

然后像这样使用它:

class BaseClass
{
};

DeriveClass<BaseClass> c;

如果不可能,有没有办法实现同样的想法?

最佳答案

是的,您可以使用模板参数作为基础,并且it compiles in MSVS if you fix the typo .

(请注意,这不是 CRTP,尽管您可能听说过。)

关于c++ - 基类和模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56062110/

相关文章:

c++ - #include <../header.h> 在 C++ 中是一种不好的做法吗?

c++ - 跨平台UTF-8 char文件数据编码/解码

c++ - Linux fork/exec 到同一目录中的应用程序

c++ - OpenGL 二十面体纹理贴图

c++ - thread_specific_ptr 多线程混淆

c++ - 共享库g++错误段错误

c++ - Libcurl 错误将接收到的数据写入磁盘/应用程序失败

c++ - setter方法错误: argument of type "const char *" is incompatible with parameter of type "char *"

伸展树(Splay Tree)的 C++ 实现

c++ - Google Mock 是一个很好的模拟框架吗?