Summary Files Commits Branches @commit @diff @stats
path: root / Year 1 / Object-oriented Programming / Solutions Sem. 08 / ex3 / DynStr.cpp
diff options
context:
space:
mode:
1 files changed, 8 insertions, 0 deletions
-rw-r--r--Year 1/Object-oriented Programming/Solutions Sem. 08/ex3/DynStr.cpp8
diff --git a/Year 1/Object-oriented Programming/Solutions Sem. 08/ex3/DynStr.cpp b/Year 1/Object-oriented Programming/Solutions Sem. 08/ex3/DynStr.cpp
index bac5c83..97a2fb4 100644
--- a/Year 1/Object-oriented Programming/Solutions Sem. 08/ex3/DynStr.cpp
+++ b/Year 1/Object-oriented Programming/Solutions Sem. 08/ex3/DynStr.cpp
@@ -48,3 +48,11 @@ DynStr::~DynStr() {
const char* DynStr::get_str() const {
return str;
}
+
+int DynStr::compare(const char* other) const {
+ int cmp = strcmp(str, other);
+ // On some compilers (gcc) strcmp returns the difference, but we want it to return -1, 0 or 1
+ if (cmp > 1) cmp = 1;
+ else if (cmp < -1) cmp = -1;
+ return cmp;
+}