Skip to content

Fixed conditional jumps and added operator overload #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

CodeS42
Copy link

@CodeS42 CodeS42 commented Jul 14, 2024

  • Added default initialization of array elements in constructor taking an unsigned int :
    this->_array = new T[this->size()]();
    By adding parentheses at the end, the elements of the array are initialized by default, as requested in the subject. Moreover, this default initialization is essential, as failure to do so will result in a conditional jump when trying to access the array elements.

  • Added destructor message, and used size() method to make the code fully coherent.

  • Added [] operator overload for constant objects :
    const T &operator[]( unsigned int index ) const
    The code must allow us to access and modify the array elements of non-constant objects, but also to access the array elements of a constant object without being able to modify them. To do this, we need 2 overloads of the [] operator (one for non-constant objects, and one for constant objects).

  • Removed _size(src.size()) in copy constructor :
    The copy constructor calls the assignment operator, which itself contains a line for copying the value of the _size attribute. Moreover, there's a condition in the assignment operator that says to copy this value only if it's not equal to 0. However, if you initialize _size directly in the copy constructor with the _size value of the src object, before calling the assignment operator, and the value copied into _size is equal to 0, you're doing something you wanted to prevent by putting the condition present in the assignment operator.

…an unsigned int; added destructor message; added [] operator overload for constant objects; used size() method; removed _size(src.size()) in copy constructor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant