它适用于struct RS : public JV<T,1>
但不适用于struct RS : public JV<T,2>
.
error: could not convert ‘{(0, j), (0, j)}’ from ‘<brace-enclosed initializer list>’ to ‘WJ<float>’
我必须超载operator,()
吗?代码:
#include<iostream>
struct B {};
template <std::size_t... Is>
struct indices {};
template <std::size_t N, std::size_t... Is>
struct build_indices
: build_indices<N-1, N-1, Is...> {};
template <std::size_t... Is>
struct build_indices<0, Is...> : indices<Is...> {};
template<class T,int N>
struct JV {
JV(B& j) : JV(j, build_indices<N>{}) {}
template<std::size_t... Is>
JV(B& j, indices<Is...>) : jit(j), F{{(void(Is),j)...}} {}
B& jit;
T F[N];
};
template<class T>
struct RS : public JV<T,2>
{
RS(B& j): JV<T,2>(j) {}
};
template<class T>
struct WJ
{
WJ(B& j) {
std::cout << "WJ::WJ(B&)\n";
}
};
int main() {
B j;
RS<WJ<float> > b2(j);
}