bigvalue_t result; result.assign(left.size() + right.size(), 0); int carry = 0; for(size_t i = 0; i < left.size(); i++) { carry = 0; for(size_t j = 0; j < right.size(); j++) { int sum = result[i+j] + (left[i]*right[j]) + carry; result[i+j] = sum%10; carry = sum/10; } result[i+right.size()] = carry; } return result; Here I used assign to allocate size of result, and result passed back normally. When I use result.reserve(left.size()+right.size());, the function runs normally inside the both for loops. Somehow when I use print out the result.size(), it is always 0. Does reserve not allocate any space?
reserveallocates space, but it doesn't create elements in the container.