1
我只想了解编译器为什么会给出这个错误以及需要更改哪些内容?我只是在玩C++ 11代码。为什么限定名称错误?
class test
{
public:
template<int N>
bool foo() { return true;}
template<int N, int... Ns>
struct table : table<N-1, N-1,Ns...> {};
template<int... Ns>
struct table<0,Ns...>
{
static constexpr bool(test::table<0,Ns...>::*fns[])() = {foo<Ns>...};
};
// below line gives the error
template<int... Ns>
constexpr bool (*test::table<0,Ns...>::fns[sizeof...(Ns)])();
};
int main()
{
}
的错误是:
error: invalid use of qualified-name test::table<0, Ns ...>::fns
这个代码有很多问题。例如,'foo'是一个“'test :: *'”,而不是“'test :: table <0, Ns...> :: *'”。这些问题中的大部分都与您显示的错误无关。 – chris
你想做什么?如果通过倒数第二行来声明'test'的成员函数,则必须给该成员函数一个非限定名称。 – JohnB
@JohnB,我认为OP正试图定义静态成员'fns'。这个定义不应该在课堂上。 – chris