/*
* Copyright ©2026 Soham Pardeshi. All rights reserved.
* Permission is hereby granted to students registered for University of
* Washington CSE 333 for use solely during Summer Quarter 2026 for
* purposes of the course. No other use, copying, distribution, or
* modification is permitted without prior written consent. Copyrights
* for third-party components of this work must be honored. Instructors
* interested in reusing these course materials should contact the author.
*/
#include "IntArray.h"
#include <iostream> // for std::cout, std::endl
#include <cstdlib> // for EXIT_SUCCESS
using std::cout;
using std::endl;
void PrintArray(const IntArray& a) {
cout << "[";
for (size_t i = 0; i < a.Size(); i++) {
cout << a.At(i) << (i + 1 < a.Size() ? ", " : "");
}
cout << "]" << endl;
}
int main(int argc, char** argv) {
IntArray a(3);
a.Set(0, 7);
a.Set(1, 8);
a.Set(2, 9);
IntArray b = a; // copy constructor: b gets its OWN deep-copied buffer
b.Set(0, 0); // changing b does NOT touch a (separate buffers)
PrintArray(a); // [7, 8, 9]
PrintArray(b); // [0, 8, 9]
IntArray c(1);
c = a; // copy assignment: c frees its old buffer, deep-copies a
PrintArray(c); // [7, 8, 9]
// All three objects clean up their own buffer automatically at end of scope.
return EXIT_SUCCESS;
}
// Compile with:
// g++ -Wall -g -std=c++17 -c IntArray.cc
// g++ -Wall -g -std=c++17 -c useintarray.cc
// g++ -Wall -g -std=c++17 -o useintarray useintarray.o IntArray.o