Hi, when completing the “spaceship operator overloading” section in the 3 part of the c++ series, my compiler kept saying that strong_ordering wasn’t a valid data type. How would I be able to fix this? I think it might have something to do with what c++ version I am running.
Code (Vscode):
#include
#include
using namespace std;
class Length {
public:
explicit Length(int value);
bool operator==(const Length& second) const;
bool operator==(int val) const;
std::strong_ordering operator<=>(const Length& second) const;
private:
int value;
};
Length::Length(int value) : value(value) {}
bool Length::operator==(const Length& second) const {
return (value == second.value);
}
bool Length::operator==(int val) const {
return ((value) == val);
}
std::strong_ordering Length::operator<=>(const Length& second) const{
return value <=> second.value;
}
int main() {
Length first{20};
Length second{20};
return 0;
}