作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我写了这个简单的代码,但它没有编译,因为比较被隐式删除。
struct Tree {
std::vector<Tree> child;
friend auto operator<=>(const Tree &a, const Tree &b) = default;
}
int main(){
Tree t;
std::cout<<(t<t)<<std::endl;
}
任何人都可以向我解释如何解决这个问题,或者至少解释为什么它不起作用吗?
编辑:用“g++ -std=gnu++2a main.cpp”编译编辑2:这是输出的错误部分(后面跟着很多很多候选行):
main.cpp: In function 'int main()':
main.cpp:31:25: error: use of deleted function 'constexpr auto operator<=>(const Tree&, const Tree&)'
31 | std::cout << (tmp < tmp) << std::endl;
| ^~~
main.cpp:12:17: note: 'constexpr auto operator<=>(const Tree&, const Tree&)' is implicitly deleted because the default definition would be ill-formed:
12 | friend auto operator<=>(const Tree &a, const Tree &b) = default;
| ^~~~~~~~
main.cpp:12:17: error: no match for 'operator<=>' (operand types are 'std::vector<Tree>' and 'std::vector<Tree>')
最佳答案
您通常不能定义具有推导返回类型的递归函数。为了推断它,您需要已经知道它,所以这是不行的。
用显式返回类型 std::weak_ordering
替换 auto
fixes the problem .
关于c++ - 递归宇宙飞船运算符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67389118/
实际上,我正在编写一个小型太空射击游戏(2.5D,俯 View )。玩家可以沿着 XZ 轴移动并通过右侧的迷你摇杆(游戏 handle )旋转宇宙飞船或查看光标位置(键盘 + 鼠标)。 因此,运动和旋
这里是初级程序员,只是想了解Ruby背后的过程sort使用飞船操作符时的方法 .希望有人能帮忙。 在以下内容中: array = [1, 2, 3] array.sort { |a, b| a b
什么是 Ruby (宇宙飞船)运算符(operator)?该运算符是否由任何其他语言实现? 最佳答案 spaceship operator将返回 1、0 或 −1,具体取决于左侧参数相对于右侧参数的
我想在 window 的中央画一艘宇宙飞船,因为它在太空中提供动力。为了滚动世界窗口,我计算了飞船的新位置,并使用 glOrtho 将一个 4000x3000 的窗口居中。我的测试是按下前进按钮并向上
我是一名优秀的程序员,十分优秀!