Skip to content

Task 6#6

Open
Trinity-142 wants to merge 2 commits into
mainfrom
task-6
Open

Task 6#6
Trinity-142 wants to merge 2 commits into
mainfrom
task-6

Conversation

@Trinity-142
Copy link
Copy Markdown
Owner

No description provided.

Comment thread 6.cpp Outdated
}

SquareMatrix operator+(const SquareMatrix& other) const {
assert(_size == other._size);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assertion is something that should never happen, but this... well it could happen, right? If user will give you the wrong matrix. I suggest to throw an exception here instead

Comment thread 6.cpp Outdated
return !(*this == other);
}

T* operator[](size_t i) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

while this will work, there are some problems with such solution.

First of all: it would be nice to have some boundary checks, when index is too big, an exception is a better solution than UB. This is true for both dimensions!

Also, returning a raw pointer to the user looks like breaking the encapsulation. He could access elements from the other Row or just call delete on it! Looks unsafe.

Let's try to think how to solve these problems.

@Trinity-142 Trinity-142 requested a review from ugliansky May 16, 2026 13:59
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.

2 participants