Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /******************************************************************************
- Online C++ Compiler.
- Code, Compile, Run and Debug C++ program online.
- Write your code in this editor and press "Run" button to compile and execute it.
- *******************************************************************************/
- #include <iostream>
- #include <vector>
- template <typename T>
- std::vector<T>& operator +(const std::vector<T>& vector1, const std::vector<T>& vector2) {
- std::vector<T> newVec;
- newVec.insert(vector1.end(), vector2.begin(), vector2.end());
- return newVec;
- }
- template <typename T>
- std::vector<T>& operator +=(std::vector<T>& vector1, const std::vector<T>& vector2) {
- vector1.insert(vector1.end(), vector2.begin(), vector2.end());
- return vector1;
- }
- using namespace std;
- int main() {
- print(std::vector<double> {6.7, -12.3, 5} + std::vector<double> {0.5, -2.7, 19});
- std::vector<double> vector {6.7, -12.3, 5};
- print((vector += std::vector<double> {0.5, -2.7}) += std::vector<double> {19});
- print(vector);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement