fork download
  1. #include <iostream>
  2. #include <algorithm>
  3.  
  4. struct myarray
  5. {
  6. myarray(unsigned size) : _size(size), _array(new int[_size]()) {}
  7.  
  8. unsigned size() const { return _size; }
  9. int& operator[](unsigned index) { return _array[index]; }
  10. int operator[](unsigned index) const { return _array[index]; }
  11.  
  12. operator int*() {return _array;}
  13. operator const int*() const { return _array; }
  14.  
  15. myarray(const myarray&) = delete;
  16. void operator=(const myarray&) = delete;
  17.  
  18. private:
  19. unsigned _size;
  20. int* _array;
  21. };
  22.  
  23. void mysort(int* arr, unsigned sz) { std::sort(arr, arr + sz); }
  24. void mysort(myarray& arr) { return mysort(arr, arr.size()); }
  25.  
  26. void display(const myarray& arr)
  27. {
  28. for (unsigned i = 0; i < arr.size(); ++i)
  29. std::cout << arr[i] << '\n';
  30. std::cout << '\n';
  31. }
  32.  
  33. int main()
  34. {
  35. myarray arr(10);
  36. for (unsigned i = 0; i < arr.size(); ++i)
  37. arr[i] = arr.size() - i;
  38.  
  39. display(arr);
  40. mysort(arr);
  41. display(arr);
  42. }
  43.  
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
10
9
8
7
6
5
4
3
2
1

1
2
3
4
5
6
7
8
9
10