I have a questions where I need to overload the + operator for vectors so that I can add two vectors together. The question I have is on how and where to write the code.

what is the definition of the + operator for STL vectors?
template<typename T, typename Allocator>
vector<T, Allocator> &operator+ (const vector<T, Allocator> &a, const vector<T, Allocator> &b)


and do I just code this outside of main?

Thanks,

what is the definition of the + operator for STL vectors?
template<typename T, typename Allocator>
vector<T, Allocator> &operator+ (const vector<T, Allocator> &a, const vector<T, Allocator> &b)
and do I just code this outside of main?

yes, you define it as a global. however, there is a logical error in your declaration; the result of operator+ is a temporary variable; you should return the temporary by value, not reference.
what does it mean to add two vectors? concatenate or add element by element?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.