Compiler can't use member aggregate initialization because C-arrays can't be copied.
To overcome this, provide a constructor for your struct:
template<int N>
struct XYarr
{
XYarr() = default; // default constructor if needed
XYarr(const double (&x_)[N], const double (&y_)[N]) {
memcpy(&x,x_,sizeof (double)*N);
memcpy(&y,y_,sizeof (double)*N);
}
double x[N],y[N];
int size() {return N;}
};
int main(int argc, char * argv[]) {
XYarr<100> a; // default constructor
double x2[100], y2[100];
auto n = XYarr<100>{x2, y2}; // init constructor
return 0;
}
There is an std::array version for comparison. std::array can be used with member aggregate initialization - so no boilerplate code, everything is simple.
template<int N>
struct XYarr_stl
{
std::array<double,N> x,y;
int size() {return N;}
};
int main(int argc, char * argv[]) {
std::array<double,100> x2_stl, y2_stl;
auto n_stl = XYarr_stl<100>{x2_stl, y2_stl};
// this will give compilation error, because array sizes will be checked at compile time
//std::array<double,200> x2_stl2, y2_stl2;
//auto n_stl2 = XYarr_stl2<100>{x2_stl2, y2_stl2};
return 0;
}
std::array<double, N>instead. Arrays can't be copied implicitly. The error message sounds like it is related to copying an array.template<int size> XYarr<size> sortSplitted(double x[], double y[]).std::arrayis generally considered to be strictly superior to C-style arrays. The problem here isn't entirely clear yet, but if it is related to assigning an array to try to copy it, you would need tostd::copyeach element instead.