From 13396e0cabaf82b918f5ff0156011663d823846c Mon Sep 17 00:00:00 2001 From: Jie Date: Wed, 26 Mar 2025 18:04:38 +0800 Subject: [PATCH] fix move function --- include/sqlConnection.h | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/include/sqlConnection.h b/include/sqlConnection.h index bb3798f..aa509d5 100644 --- a/include/sqlConnection.h +++ b/include/sqlConnection.h @@ -78,14 +78,26 @@ public: SqlConnection& operator=(const SqlConnection& other) = delete; SqlConnection(SqlConnection&& other){ - other.Close(); - this->Connect(other.ip, other.port, other.username, other.password, other.database_name); + this->ip = std::move(other.ip); + this->port = std::move(other.port); + this->username = std::move(other.username); + this->password = std::move(other.password); + this->database_name = std::move(other.database_name); + this->mysql_client = other.mysql_client; + mysql_init(&(other.mysql_client)); } SqlConnection& operator=(SqlConnection&& other){ if(this != &other){ - this->Connect(other.ip, other.port, other.username, other.password, other.database_name); - other.Close(); + this->Close(); + this->ip = std::move(other.ip); + this->port = std::move(other.port); + this->username = std::move(other.username); + this->password = std::move(other.password); + this->database_name = std::move(other.database_name); + this->mysql_client = other.mysql_client; + mysql_init(&other.mysql_client); + } return *this; }