I'm trying to work with dynamic arrays. When I try to overload the "=" operator it does not work. When debugging the file it doesn't execute the void function to overload the operator.
#include <iostream>
using namespace std;
class cppArray {
public:
    cppArray(int size);
    ~cppArray();
    int read(int index);
    void write(int content, int index);
    void operator=(cppArray& s);
    int search(int target);
    int size();
private:
    int* myArray;
    int arraySize;
};
cppArray::cppArray(int size) {
    myArray = new int[size];
    arraySize = size;
}
//delete the memory space assigned to myArray 
cppArray::~cppArray() {
    delete[] myArray;
    myArray = 0;
}
int cppArray::read(int index) {
    if (index < arraySize) {
        return myArray[index];
    }
    else {
        cout << "Out of range" << endl;
        exit(1);
    }
}
Here I'm trying to copy the content of the original array to an auxiliar one, and then redefine the size of the original array so I can add more content to the original array
void cppArray::write(int content, int index) {
    if (index < arraySize) {
        myArray[index] = content;
    }
    else {
        cppArray auxArray(arraySize);
        auxArray.myArray = myArray;
        delete[] myArray;
        arraySize = index + 1;
        myArray = new int[arraySize];
        myArray = auxArray.myArray;
        myArray[index] = content;
    }
}
I'm pretty sure this is wrong, but I can't figure out a way to overload it correctly
void cppArray::operator=(cppArray& s) {
    delete[] s.myArray;
    s.myArray = new int[arraySize];
    for (int i = 0; i < arraySize; i++)
    {
        myArray[i] = s.myArray[i];
    }
}
int cppArray::size() {
    return arraySize;
}
int main(int argc, char** argv) {
    cppArray dsArray(3);
    dsArray.write(1, 0);
    dsArray.write(2, 1);
    dsArray.write(3, 2);
    dsArray.write(4, 3);
    for (int i = 0; i < dsArray.size(); i++) {
        cout << dsArray.read(i) << "\t";
    }
    cout << endl;
    return 0;
}```
 
    