C++:结构命名标准
我应该如何命名结构及其变量?这包括对象内部的结构...
谢谢。
How should I name structs and their variables? This include structs inside objects...
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
找到你喜欢的风格并坚持下去。就这么简单。我这样做:
结构体和类的第一个字符大写,而内部的变量则不然。
但话又说回来,这就是我的风格,找到适合自己的风格并坚持下去。没什么可说的了。
Find a style that you like and stick to it. Its as simple as that. I do it like this:
Struct's and classes have their first character capitalized, variables inside don't.
But again, this is my style, find a style that suits you and stick to it. Nothing more to be said.
这是我认为非常完整的命名约定的完整列表:
this
。建造。这适用于 C#,但也适用于 Java/C++。如果您想标准化您的代码,我建议您查看高完整性 C++ 编码标准手册。
对于外壳标识符,您应该按如下方式进行操作:
This is complete list for Naming conventions that I consider to be very complete:
this
. construction.This is for C# but also apply for Java/C++. If you want to standarize your code I recommend you to see the HIGH·INTEGRITY C++ CODING STANDARD MANUAL.
For casing identifiers you should do it as follow:
使您的风格与周围的人保持一致——在合理的范围内,您对结构和变量使用哪种命名方案并不重要,只要您团队中的每个人都在做一致的事情。
就我个人而言,我这样命名结构:
FunkyContainer
和这样的变量:
ratherUsefulVariable
但是你必须调整你所做的事情以适应房屋风格,否则你会破坏一致性您团队的代码。
附带说明一下,你没有“对象内部的结构”——你可以有嵌套结构,它们是结构内部的结构,但这不是同一件事。对象是结构的实例,而不是结构本身。 (显然,对象也可以是类的实例,但这与此处进行区分的目的无关。)
Harmonise your style with the people around you -- within reason, it doesn't matter which naming scheme you use for structs and variables, provided everyone on your team is doing a consistent thing.
Personally, I name structs like this:
FunkyContainer
And variables like this:
ratherUsefulVariable
But you have to adapt what you do to fit the house style, or you'll ruin the consistency of your team's code.
As a side note, you don't have "structs inside objects" -- you can have nested structs, which are structs inside structs, but that's not the same thing. An object is an instance of a struct, not the struct itself. (Objects can also be instances of classes, obviously, but that's irrelevant for the purpose of making the distinction here.)
我熟悉的任何命名标准都是针对平台、库等的。例如Windows SDK有标准,CRT有标准,MFC有标准。
我没见过 C++ 的标准。也许您应该看看其他人在您的特定平台上使用的命名约定。
Any naming standard I'm familiar with are for the platform, library, etc. For example, Windows SDK has a standard, the CRT has a standard, and MFC has a standard.
I've seen no standard for C++. Perhaps you should look at what naming conventions others are using on your particular platform.