Implement a copy constructor to prevent double-free errors and undefined behavior caused by shallow copies of dynamically allocated resources.