模板类中的静态方法
static method in template class
本文关键字:静态方法 更新时间:2023-10-16
我有一个像下面这样的class
template<class T>
class Student
{
public:
static Student& Instance();
}
template<class T>
Student<T>& Student<T>::Instance()
{
...
return student;
}
返回LNK2001错误。我可以这样用吗?
你的代码模棱两可,所以我试着猜测你的问题。如果您在Student.h中声明类Student并在Student.cpp中实现方法Instance(),那就是您的问题。在Student.h.
要么Student<T>::Instance
应该在头文件中,要么你应该在.cpp文件中提供Student<>
方法的专门化
相关文章:
- 尝试了解在导入的静态方法上使用删除方法时的错误
- 如何通过命名空间调用非静态方法
- 如何在没有实例的情况下获取非静态方法的类型?
- 调用从模板派生的类的静态方法,而不指定模板
- 如何在 c++ 中异步调用静态方法?
- C++ 将静态方法转换为简单方法
- 从另一个标头中的标头调用静态方法
- C++中静态方法的局部变量范围
- 如何启用使用另一个类的静态方法的模板函数的自动推导,从而消除冗长的调用方代码
- 使用本机 JNI 静态方法实现C++ Java 运行时错误
- 当只有静态方法受到影响时,如何解决C++中的链接器错误?
- 静态变量在同一个翻译单元中被静态方法使用时是否保证被初始化?
- 为什么链接器报告全局函数的乘法定义符号,而不是类静态方法
- 从部分专用模板方法调用模板非静态方法
- 如何使用 c++ 在 cocos2dx 中定义非静态方法
- 使用 CMake 的静态方法链接错误
- 在子类上调用模板化静态方法时获取类的类型名
- 仅具有公共静态方法的帮助程序类
- 调用没有主体的未实现静态方法
- 如何从C 的朋友类访问私有静态方法