如何在标题和CPP之间拆分静态/模板类
How to split a static/template class between header and cpp?
这是我拥有的静态/模板函数:
template<class T>
static T *createWidget(Vec pos, Module *module, ModuleWidget *moduleWidget, int paramId, float minValue, float maxValue, float defaultValue) {
T *widget = ParamWidget::create<T>(pos, module, paramId, minValue, maxValue, defaultValue);
moduleWidget->mRandomModeWidgets[paramId] = widget;
widget->Module = module;
widget->ModuleWidget = moduleWidget;
return widget;
}
,但我想将声明放在.h
上,并在.cpp
上进行定义。
尝试:
template<class T>
static T *createWidget(Vec pos, Module *module, ModuleWidget *moduleWidget, int paramId, float minValue, float maxValue, float defaultValue);
和:
template<class T>
static T *MyClasss:createWidget(Vec pos, Module *module, ModuleWidget *moduleWidget, int paramId, float minValue, float maxValue, float defaultValue) {
T *widget = ParamWidget::create<T>(pos, module, paramId, minValue, maxValue, defaultValue);
moduleWidget->mRandomModeWidgets[paramId] = widget;
widget->Module = module;
widget->ModuleWidget = moduleWidget;
return widget;
}
,但它说可能在此处未指定存储类。
我在哪里错了?
,但它说可能在此处指定存储类。
我在哪里错了?
静态成员函数(是否模板(只能在类定义中声明静态。您正在尝试在类别定义之外声明静态功能静态。static
关键字在类定义之外具有不同的含义。只需将其删除:
template<class T>
T *MyClasss::createWidget(params...) {
^ ^^ alśo note that there must be two colons in the scope resolution operator
no static
还请记住,在任何翻译单元中使用的模板实例必须在定义该模板的翻译单元中实例化。这可以通过在该单独的CPP文件中的显式实例化来实现。
相关文章:
- 如果C++类在类方法中具有动态分配,但没有构造函数/析构函数或任何非静态成员,那么它仍然是POD类型吗
- #为""定义宏;静态";针对不同的上下文
- cmake如何在fedora工作站中找到boost静态库包
- 静态数据成员的问题-修复链接错误会导致编译器错误
- 将公共但非静态的成员函数与ALGLIB集成
- cmake在我的项目中所需的所有静态库都不成功
- C++从另一个类访问公共静态向量的正确方法是什么
- 基于boost的程序的静态链接——zlib问题
- 在静态库中嵌入类方法
- Qt C++静态thread_local QNetworkAccessManager是线程应用程序的好选择吗
- 如何在C++中获得"静态纯虚拟"功能?
- 私有类型的静态常量成员
- 使用gcc从静态链接的文件中查找可选符号
- C++将向量的向量拆分为向量的N个子向量
- 在 .h 文件中的类中声明静态变量和在.cpp文件中声明"global"变量有什么区别
- 如何在C++中使用非静态成员函数作为回调函数
- 如何在标题和CPP之间拆分静态/模板类
- 如何在声明和定义中拆分静态lambda
- C++ OpenMP:将 for 循环拆分为静态偶数块,并在最后连接数据
- 无法拆分头文件和源文件中具有静态成员函数的类