Если разрешение перегрузки для b дает пригодный для использования кандидат и может быть явно преобразовано в T с помощью static_cast, синтезированное сравнение будет static_cast(a б).
Однако следующий код не работает:
Код: Выделить всё
struct AA
{
int a;
int operator (const AA &other) const
{
if (a < other.a)
return -7;
else if (a > other.a)
return 5;
else
return 0;
}
};
struct BB
{
AA b;
int operator (const BB &other) const = default;
};
int main ()
{
BB b1{4}, b2{6};
std::cout
Подробнее здесь: [url]https://stackoverflow.com/questions/79902461/defaulted-three-way-comparison-operator-with-a-return-type-different-from-the-co[/url]
Мобильная версия