静态constexpr,静态const,constexpr,const,constinit?
如果我需要在多个函数和东西上引用两个4x4浮子矩阵的大小,即128个矩阵,那么不使用宏的最佳方法是什么。我知道,对于像这样的琐碎的事情,这并不重要,但它只是为了更好地了解C ++具有的所有内容(const,constexpr,consteval,consteval,constinit,static等)。而且,由于该变量仅在一个文件中引用,因此应该是静态的,但是我听到某个地方constexpr或const global变量自动静态或类似的东西(我可能完全是错误的,所以如果是这样,请纠正我)。
话虽如此,只有一个文件中的函数中的一个名称下的数字在一个文件中只有一个数字之间有什么区别,哪个是最好的区别? (同样,没有宏):
const size = 128;
constexpr size = 128;
constinit size = 128;
static const size = 128;
static constexpr size = 128;
static constinit size = 128;
If I need to reference the size of two 4x4 float matrices, which is 128, across multiple functions and stuff, what is the best way to do it that doesn't use macros. I know that for something trivial like this it doesn't really matter, but its just for getting a better understanding of all of the stuff C++ has (const, constexpr, consteval, constinit, static, etc). And since that variable is only going to be reference inside one file, it should be static, but I heard somewhere that constexpr or const global variables are automatically static or something like that (I could be completely wrong so correct me if so).
With all that said, what are the difference between and which is the best for just keeping a number under a name across functions inside only one file? (again, with no macros):
const size = 128;
constexpr size = 128;
constinit size = 128;
static const size = 128;
static constexpr size = 128;
static constinit size = 128;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论