对于以下代码:
template<class... Parameter> struct Outer
{
template<Parameter... Value> struct Inner
{
static bool Member;
};
};
template<class... Parameter>
template<Parameter... Value>
bool Outer<Parameter...>::Inner<Value...>::Member = true;
int main()
{
Outer<int>::Inner<0>::Member = false;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
GCC 7.3.0 报告:
error: expansion pattern 'Value' contains no argument packs
bool Outer<Parameter...>::Inner<Value...>::Member = true;
Run Code Online (Sandbox Code Playgroud)
和 Visual Studio 16.7.2,类似地,大约相同的Value
参数包:
error C3546: '...': there are no parameter packs available to expand
Run Code Online (Sandbox Code Playgroud)
如果在同一代码Parameter
中不是参数包,或者Value
不依赖于Parameter
.
为什么会发生这些错误?这种情况是否需要一些特殊的语法?
我知道,因为c++17
它可以通过使用inline
关键字定义类中的成员来解决。但是c++11
,如果可能的话,我希望我的代码与 …