Error C2100 - Illegal Indirection
Don't forget your operator precedence rules. It seems that you want:
(*TempArray2)[i]
Otherwise your expression *TempArray2[i]
is considered as *(TempArray2[i])
and I suppose your NumericArray<T>
type doesn't have the unary *
operator overloaded.
In *TempArray2[i]
, the *
is applied to TempArray[2]
because of the precedence rules, and there's a fair chance that the array elements don't have a unary *
operator.
But your use of dynamic allocation and then dereferencing to return by value means that you have a memory leak.
(You don't need new
to create objects in C++ - you probably don't need to use it in main
either.)
This would be better (and avoids the whole indirection issue):
template <typename T> NumericArray<T> NumericArray<T>::operator * (int factor) const{ NumericArray<T> TempArray(Size()); for (int i = 0; i < Size(); i++) { TempArray[i] = GetElement(i) * factor; } return TempArray;}