In *TempArray2[i] * applies to TempArray[2] due to priority rules, and there is a fair likelihood that array elements do not 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 create objects in C ++ - you probably don't need to use it in main .)
This would be better (and avoid the whole problem of indirection):
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; }
molbdnilo
source share