fork(2) download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class Array
  6. {
  7.  
  8. public:
  9.  
  10. int *ptr;
  11. int one,two;
  12. Array(int arr[])
  13. :
  14. one(0), two(0)
  15. {
  16. ptr=arr;
  17. }
  18.  
  19.  
  20. int &operator[](int index)
  21. {
  22. one=index;
  23. return ptr[index];
  24. }
  25. Array & operator=(int x){
  26. two=x;
  27. return *this;
  28. }
  29. };
  30.  
  31. std::ostream& operator<<(std::ostream& stream, const Array& array)
  32. {
  33. stream << "( " << array.one << ", " << array.two << ": ";
  34. if (array.ptr)
  35. stream << *(array.ptr);
  36. stream << ")";
  37. return stream;
  38. }
  39.  
  40. int main(void)
  41. {
  42. int y[]={1,2,3,4};
  43. Array x(y);
  44. cout << "Before assigning one element: " << x << endl;
  45. x[1]=5;
  46. cout << "After assigning one element: " << x << endl;
  47. x = 7;
  48. cout << "After operator=: " << x << endl;
  49. }
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
Before assigning one element: ( 0, 0: 1)
After  assigning one element: ( 1, 0: 1)
After  operator=:             ( 1, 7: 1)