Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. /******************************************************************************
  2.  
  3. Online C++ Compiler.
  4. Code, Compile, Run and Debug C++ program online.
  5. Write your code in this editor and press "Run" button to compile and execute it.
  6.  
  7. *******************************************************************************/
  8.  
  9. #include <iostream>
  10. #include <vector>
  11.  
  12. template <typename T>
  13. std::vector<T>& operator +(const std::vector<T>& vector1, const std::vector<T>& vector2) {
  14. std::vector<T> newVec;
  15. newVec.insert(vector1.end(), vector2.begin(), vector2.end());
  16. return newVec;
  17. }
  18.  
  19. template <typename T>
  20. std::vector<T>& operator +=(std::vector<T>& vector1, const std::vector<T>& vector2) {
  21. vector1.insert(vector1.end(), vector2.begin(), vector2.end());
  22. return vector1;
  23. }
  24.  
  25.  
  26. using namespace std;
  27.  
  28. int main() {
  29. print(std::vector<double> {6.7, -12.3, 5} + std::vector<double> {0.5, -2.7, 19});
  30. std::vector<double> vector {6.7, -12.3, 5};
  31. print((vector += std::vector<double> {0.5, -2.7}) += std::vector<double> {19});
  32. print(vector);
  33.  
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement