From 1fd5b857a7d3829270a0681d4af69fdd33590ec1 Mon Sep 17 00:00:00 2001 From: Carryyyrr <158794202+Carryyyrr@users.noreply.github.com> Date: Mon, 26 May 2025 17:30:24 +0800 Subject: [PATCH] Update UserInfo.cpp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit strcmp在本地编译器上好像不行?? --- UserInfo.cpp | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/UserInfo.cpp b/UserInfo.cpp index 9b9f8c6..ce62bf6 100644 --- a/UserInfo.cpp +++ b/UserInfo.cpp @@ -21,19 +21,29 @@ namespace trainsys { memcpy(this->password, rhs.password, MAX_PASSWORD_LEN + 1); } - UserInfo &UserInfo::operator =(const UserInfo &rhs) { - /* Question */ + UserInfo& UserInfo::operator =(const UserInfo& rhs) { + if (this != &rhs) { + this->userID = rhs.userID; + this->privilege = rhs.privilege; + memcpy(this->username, rhs.username, MAX_USERNAME_LEN + 1); + memcpy(this->password, rhs.password, MAX_PASSWORD_LEN + 1); + } + return *this; } - bool UserInfo::operator ==(const UserInfo &rhs) const { - /* Question */ + bool UserInfo::operator ==(const UserInfo& rhs) const { + return userID == rhs.userID && + strcmp(username, rhs.username) == 0 && + strcmp(password, rhs.password) == 0 && + privilege == rhs.privilege; } - bool UserInfo::operator !=(const UserInfo &rhs) const { - /* Question */ + bool UserInfo::operator !=(const UserInfo& rhs) const { + return !(*this == rhs); } - bool UserInfo::operator <(const UserInfo &rhs) const { - /* Question */ + bool UserInfo::operator <(const UserInfo& rhs) const { + return userID < rhs.userID; } } // namespace trainsys +