昨天我试图让我的全局变量看起来更好,我想出了这个。
// 事件.hpp
namespace GEngine{
namespace Event{
struct _Mouse{
int mouse_x;
int mouse_y;
};
extern GEngine::Event::_Mouse Mouse; // Inside
}
}
// Main.cpp
// 放
GEngine::Event::Mouse.mouse_x = 100;
GEngine::Event::Mouse.mouse_y = 50;
// 得到
int foo = GEngine::Event::Mouse.mouse_x;
---- 对 -----
namespace GEngine{
namespace Event{
struct _Mouse{
int mouse_x;
int mouse_y;
};
}
}
extern GEngine::Event::_Mouse Mouse; // Outside
......
// Main.cpp
// 得到
Mouse.mouse_x = 100;
Mouse.mouse_y = 50;
// 放
int foo = Mouse.mouse_x;
你会选择哪种编码风格?简单明了还是相反?
并且更准确一点。你会选择命名你的全局变量 GEngine::Event::Mouse.mouse_x 还是 Mouse.mouse_x ?