![](/img/trans.png)
[英]C++ 17 How to specialize static function template in class template
[英]How to specialize a static function of a class template?
当我尝试写这样的东西时:
#include <iostream>
template <class T>
class A
{
public:
static void doit();
};
template <>
static void A<int>::doit()
{
std::cout << "int" << std::endl;
}
template <>
static void A<double>::doit()
{
std::cout << "double" << std::endl;
}
int main()
{
A<int>::doit();
A<double>::doit();
}
全班专业都可以。 我只想知道有什么方法可以专门化静态函数?
在声明中,您只能指定一次static
关键字。
尝试这个:
template<>
void A<int>::doit()
{
std::cout << "int" << std::endl;
}
template<>
void A<double>::doit()
{
std::cout << "double" << std::endl;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.