比较两个SDL_point
Compare two SDL_point?
我注意到我不能直接比较两个SDL_point
:
SDL_Point a = {1, 2};
SDL_Point b = {1, 2};
if (a == b) std::cout << "a = bn"; // Doesn't compile.
if (a.x == b.x && a.y == b.y) // I have to do this instead.
std::cout << "a = bn";
我想重载operator==
,但由于SDL_Point
是 SDL 的一部分,我不确定如何,因为我可能想在游戏的许多不同类别中使用重载运算符。
这样做的正常方法是什么?
只需有一个实用程序或sdl_utility标头来定义内联运算符:
inline bool operator==(SDL_Point const &a, SDL_Point const &b)
{
return a.x == b.x && a.y == b.y;
}
inline bool operator!=(SDL_Point const &a, SDL_Point const &b)
{
return !(a == b);
}
您必须在要使用运算符的任何源文件中包含此标头。
相关文章:
- 在VS代码中交叉编译Windows与Linux上的MinGW的SDL程序
- Mix_Init和Mix_OpenAudio SDL之间的区别是什么
- SDL 窗口不会弹出
- SDL 操纵杆按钮按下/C++
- VSCode IntelliSense无法识别SDL框架的SDL_image扩展库
- C++/SDL "initial value of reference to a non-const must be an lvalue"
- SDL 映像:无法打开映像,仅显示错误消息
- 如何在 3D OpenGL 场景上绘制 SDL 2D 矩形?
- "Undefined symbols for architecture x86_64" 在 SDL 2 (macOS) 中
- 为什么 SDL 在 Mac 上比 Linux 慢得多?
- 在 OSX 上打开 SDL 窗口时不要打开终端窗口
- SDL + OpenGL ES 2.0 使用着色器显示纹理
- SDL GPU 为什么将两个图像分成两个单独的循环更快?
- Qt5 部署"procedure entry point could not be located"
- 在 cmake 中找不到 SDL 库
- SDL/C++: 如何平滑但随机地移动矩形?
- 如何与 SDL 库链接?
- 我想获取点的属性,它报告错误 C3867:"point::output_x":非标准语法;使用"&"创建指向成员的指针
- 为什么我的C++代码不呈现 SDL 矩形?
- 如何从内存中分配GDI+ POINT类地址?