fork(1) download
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5. #define SIZE (1)
  6. struct arry
  7. {
  8. private:
  9. int *n = NULL;
  10. int size;
  11. public:
  12. arry() { n = new int[SIZE]; size = SIZE; }
  13. ~arry() { delete [] n; }
  14. inline int length() const { return size; }
  15. int& operator [] (int p) const { return n[p]; }
  16. void incSize() {
  17. int *temp = new int[size + 1];
  18. memcpy(temp, n, sizeof(int) * size);
  19. delete [] n;
  20. n = temp;
  21. size++;
  22. }
  23. };
  24.  
  25. int main() {
  26.  
  27. arry dyn;
  28.  
  29. dyn[0] = 100;
  30.  
  31. cout << dyn.length() << endl;
  32.  
  33. dyn.incSize();
  34.  
  35. cout << dyn.length() << endl;
  36.  
  37. dyn[1] = 200;
  38.  
  39. cout << dyn[0] << endl;
  40. cout << dyn[1] << endl;
  41.  
  42. return 0;
  43. }
Success #stdin #stdout 0s 3428KB
stdin
Standard input is empty
stdout
1
2
100
200