samedi 1 juillet 2017

conflicting declaration of class static member

#include <iostream>
#include <utility>

using namespace std;

template<typename>
struct Class1;

template<size_t...Is>
struct Class1<index_sequence<Is...>> {
    template<size_t N>
    struct Holder {
        constexpr Holder(int const(&Ns)[N])
            : data{someCalc(Ns[Is], Is)...} {
        }

        int data[N];
    };
};

template<int...Ns>
class Class2 {
public:
    static constexpr const int mNs[] = {Ns...};
    static constexpr const typename Class1<make_index_sequence<sizeof...(Ns)>>::template Holder<sizeof...(Ns)> Hs{mNs};
};

template <int...Ns>
constexpr const typename Class1<make_index_sequence<sizeof...(Ns)>>::template Holder<sizeof...(Ns)> 
        Class2<Ns...>::Hs; // error: conflicting declaration

int main() {
    cout << &Class2<1, 2, 3>::Hs << endl;
}

This is the simplified version of my code. It's compiles in VS because VS does not comformant to this shit. But failed to compile under g++ 6.3. What exactly is the type of Class2<...>::Hs?

Basically I need to initialize an array using another array's element and the index of that element at compile time. So if there is a better way, It would be better.

Aucun commentaire:

Enregistrer un commentaire