Guest User

Untitled

a guest
Jan 24th, 2020
66
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct Array {
  5. int size;
  6. int* data;
  7. Array(int x) {
  8. std:cout << "Constuctor\n";
  9. size = x;
  10. data = new int[size];
  11. }
  12. Array(const Array& A) {
  13. std:cout << "Copy constuctor\n";
  14. if (size != A.size && data != A.data) {
  15. size = A.size;
  16. data = new int[size];
  17. for (int i = 0; i < size; i++) {
  18. data[i] = A.data[i];
  19. }
  20. }
  21. }
  22. ~Array() {
  23. std:cout << "Destructor\n";
  24. delete[] data;
  25. }
  26. };
  27.  
  28.  
  29. int main() {
  30. Array a(10);
  31. Array b(a);
  32. return 0;
  33. }
RAW Paste Data