那么全局和本地包含c ++文件的顺序呢?[关闭](what about the order of global vs local include files in c++ [closed])

编程入门 行业动态 更新时间:2024-10-26 14:38:59
那么全局和本地包含c ++文件的顺序呢?[关闭](what about the order of global vs local include files in c++ [closed])

是否有一个推荐的做法,例如全球包括应包括本地包括。 全局我的意思是#include <iostream>和本地#include "myhdr.h" 。 这是一些喜欢的秩序,为什么?

Is there a recommended practice that for example global includes shall go befor local includes. By global I mean #include <iostream> and local #include "myhdr.h". Is it some prefered order and why?

最满意答案

是的,有建议。 他们之中有一些是:

顺序 :如果你在MyClass.cpp中,首先放置“MyClass.h”,然后是C-headers,然后是STL头,然后是你的项目的头。 内部顺序 :在每个类别中,使用字母顺序。 语法 :对于C和STL使用#inlcude <> ,对于您自己的头文件使用#include "" 。

他们应该看起来像这样:

#include "MyClass.h" #include <time.h> #include <iostream> #include <vector> #include "MyFolder/MyAwesomeClass.h" #include "MyOtherFolder/MyOtherClass.h"

有关良好编码风格的更多建议,请参阅Google的C ++风格指南 。 他们给出了一个很好的解释, 为什么你应该在这一节中做到这一点 。

Yes, there are recommendations. Some of them are:

Order: If you're in MyClass.cpp, put "MyClass.h" first, then C-headers, then STL headers, then your project's headers. Internal order: In each of these categories, use alphabetical order. Syntax: Use #inlcude <> for C and STL and #include "" for your own headers.

They should look something like this:

#include "MyClass.h" #include <time.h> #include <iostream> #include <vector> #include "MyFolder/MyAwesomeClass.h" #include "MyOtherFolder/MyOtherClass.h"

For more recommendations on good coding style you can take a look at Google's C++ Style Guide. They give a good explanation on why you should do this in this section.

更多推荐

本文发布于:2023-08-04 11:38:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1415347.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:全局   顺序   文件   order   global

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!