我已经看过一些类似的问题,还没有找到适用于我的用例的解决方案。我有一个constexpr变量,我想使用默认参数作为模板,但似乎无法正常工作:
// Test.hpp
class Test
{
public:
template <bool val = false>
constexpr static bool MY_BOOL = val;
};
// Test.cpp
#include "Test.hpp"
#include <iostream>
int main()
{
std::cout << Test::MY_BOOL << "\n";
return 0;
}
g ++编译器错误:
Test.cpp: In function ‘int main()’:
Test.cpp:6:29: error: missing template arguments before ‘<<’ token
std::cout << Test::MY_BOOL << "\n";
请让我知道我在做什么错/如果可以解决。谢谢!
仅在功能模板中可以省略模板名称后的模板参数列表。对于变量模板,类模板或别名模板,即使您不想提供任何显式参数,也至少需要一个空列表<>
。