My answer here to another question about arrays explains why you don't want to use arrays.
As I said in this answer, you cannot assign an array as you try:
float g[100]; g = foo(); // illegal, assigning to arrays is not allowed
Another strange limitation on arrays is that you are not allowed to return them from functions:
float foo()[100];
Also note that when you declare a function of type float arr_sub(float a[100][100]) , you might think that you are passing an array by value, but in fact it raises one more of the strange exceptions created for arrays. In C and C ++, whenever you declare a formal parameter of a function as an array, the type changes from "array" to "pointer to the type of the element of the array."
Since arrays do not behave as they should, you should use std :: array or std :: vector instead:
std::array<float,100> foo();
To make multidimensional arrays you can use:
std::array<std::array<float,100>,100> g;
Although this is a bit cumbersome, so you can type it:
typedef std::array<std::array<float,100>,100> Matrix; Matrix ClassArray::arr_sub(Matrix a, Matrix b) { ... } Matrix g; g = cm.arr_sub(T,W);
And if you have a compiler that supports C ++ 11, you can even create a template type alias:
template<typename T,int Rows,int Columns> using Matrix2d = std::array<std::array<T,Columns>,Rows>; Matrix2d<float,100,100> g;
Performance Note
There is one reason why you might not want to return the value of std :: array by value. If the array is large, then when copying data from the return value to the variable to which you assigned it, there can be a significant execution cost. If this ever turns out to be a problem for you, then the solution with std :: array will be the same as for other large types; use the 'out' parameter instead of returning by value.
void arr_sub(Matrix a, Matrix b, Matrix &result); Matrix g; arr_sub(T,W,g);
This does not apply to std :: vector, because std :: vector can use move semantics so as not to copy all its elements.