So recently I tried to make a following struct:
template<int... Factors>
struct Data
{
static constexpr int arr[sizeof...(Factors)] = {Factors...};
};
int main()
{
Data<1, 2, 3> p;
cout << p.arr[0] << " " << p.arr[1] << " " << p.arr[2] << endl;
return 0;
}
And it works fine.
However if I switch static constexpr int arr[sizeof...(Factors)] = {Factors...}; with static constexpr std::array<int, sizeof...(Factors)> arr {Factors...}; the code above sends me an
undefined reference to 'Data<1,2,3>::arr'
error.
Since I am fairly new to variadic templates I was wondering what's the difference between those two, and why does the error occurs?
Aucun commentaire:
Enregistrer un commentaire