When I use attempt to use the spaceship operator I get issues. Primarily ‘operator<=>’ returns “Function definition for ‘operator<=>’ not found” if I change this to some non-spaceship operator such as a bool like ‘>=’ I don’t get the same issue. the .cpp file looks to match but the header always returns an error.
Sometimes randomly std::strong_ordering in the same line returns one of many issues, either needing ‘#include ’ (which is included) or stating that it is not a member of the std namespace. This issue is weird and sometimes go away when I tab into the cpp file and back. Its inconsistent.
The cpp file itself does not appear to return errors, and yes, I am using C++20
Length.h
#ifndef ADVANCED_LENGTH_H
#define ADVANCED_LENGTH_H
#include <compare>
class Length
{
public:
explicit Length(int value);
bool operator==(const Length& other) const;
bool operator==(int other) const;
bool operator!=(int other) const;
std::strong_ordering operator<=>(const Length& other) const;
private:
int value;
};
#endif
Length.cpp
#include "Length.h"
Length::Length(int value) : value(value) {}
bool Length::operator==(const Length& other) const
{
return value == other.value;
}
bool Length::operator==(int other) const
{
return value == other;
}
bool Length::operator!=(int other) const
{
return !(value == other);
}
std::strong_ordering Length::operator<=>(const Length& other) const
{
return std::strong_ordering();
}