Skip to content

Commit 3c83a98

Browse files
authored
added virtual destructor and std::move() for string constructor parameter for optimization (for more details look out for comment in file)
1 parent 1eb4769 commit 3c83a98

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

rider.hpp

+17-10
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,21 @@
22
#include "common.hpp"
33

44
class Rider {
5-
string name;
6-
RATING rating;
5+
string name;
6+
RATING rating;
77
public:
8-
Rider(string pName, RATING pRating) : name(pName), rating(pRating) {}
9-
string getRiderName() {
10-
return name;
11-
}
12-
RATING getRating() {
13-
return rating;
14-
}
15-
};
8+
/* Moving (std::move()) a string involves transferring ownership of the internal data from the source to the destination, which is generally much faster than copying the data.
9+
This is particularly beneficial for objects like std::string that manage dynamically allocated memory. */
10+
Rider(string pName, RATING pRating) : name(std::move(pName)), rating(pRating) {
11+
}
12+
13+
const string& getRiderName() const {
14+
return name;
15+
}
16+
17+
RATING getRating() const {
18+
return rating;
19+
}
20+
21+
virtual ~Rider() = default; // Added virtual destructor
22+
};

0 commit comments

Comments
 (0)