那么全局和本地包含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.
更多推荐
发布评论