Overload operator '+' to add two arrays in C++
问题 I want to add two arrays by simply writing: int a[4] = {1,2,3,4}; int b[4] = {2,1,3,1}; int sum[4] = a + b; I wrote this function but I got an error int* operator+(const uint32& other) const{ uint32 sum[n]; for(int i=0; i<n; i++){ sum[i] = (*this[i]) + other[i]; } return sum; } Could you help me on this? Thanks in advance. 回答1: This is probably wrong, but it appears to work (C++11): #include <iostream> #include <array> using namespace std; template <class T> T operator+(const T& a1, const T&