Advertisement
Alhiris

Untitled

Jun 8th, 2020
893
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. class cls
  4. {    int *v,nr;
  5. public:cls(int i=0):nr(i),v(new int[i]){for(int j=0;j<nr;j++){v[j]=3*j;} };
  6.        ~cls(){delete[] v;};
  7.        int size(){ return  nr;};
  8.        int &operator[](int i){return v[i];};
  9.        cls operator+(cls y){
  10.                             cls x(size());
  11.                             for(int i=0;i<size();i++){x[i]=v[i]+y[i];}
  12.                             return x;}
  13. };
  14.  
  15. int main()
  16. {   cls x(10),y=x,z;
  17.     x[3]=y[6]=-15;
  18.     z=x+y;
  19.     for(int i=0;i<x.size();i++){        cout<<z[i]<<' ';}
  20.     return 0;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement