header-files

Tools to find included headers which are unused? [closed]

霸气de小男生 提交于 2019-11-26 19:42:09
I know PC-Lint can tell you about headers which are included but not used. Are there any other tools that can do this, preferably on linux? We have a large codebase that through the last 15 years has seen plenty of functionality move around, but rarely do the leftover #include directives get removed when functionality moves from one implementation file to another, leaving us with a pretty good mess by this point. I can obviously do the painstaking thing of removing all the #include directives and letting the compiler tell me which ones to reinclude, but I'd rather solve the problem in reverse

Best practices for use of C++ header files [closed]

我怕爱的太早我们不能终老 提交于 2019-11-26 19:31:20
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 6 years ago . I have the following doubts on header files usage. 1 - Include guards placing after comments /* Copyright Note and licence information

Writing function definition in header files in C++

大憨熊 提交于 2019-11-26 18:53:29
问题 I have a class which has many small functions. By small functions, I mean functions that doesn't do any processing but just return a literal value. Something like: string Foo::method() const{ return "A"; } I have created a header file "Foo.h" and source file "Foo.cpp". But since the function is very small, I am thinking about putting it in the header file itself. I have the following questions: Is there any performance or other issues if I put these function definition in header file? I will

How to make Xcode find file FacebookSDK.h?

爷,独闯天下 提交于 2019-11-26 18:08:26
问题 It says "FacebookSDK/FacebookSDK.h file not found" Yet I can jump-to-definition on the #import and it takes me to the file. And once I added the #import it now knows what FBFriendPickerDelegate is and it now doesn't have an error on that line. I have the facebookSDK.framework in my project and in the right folder. It's SDK 3.1. I tried adding search paths to /FacebookSDK and /FacebookSDK.framework and /FacebookSDK/Versions/A/Headers etc. I also tried #import "FacebookSDK.framework/Versions/A

Pros & Cons of putting all code in Header files in C++?

旧街凉风 提交于 2019-11-26 18:04:51
问题 You can structure a C++ program so that (almost) all the code resides in Header files. It essentially looks like a C# or Java program. However, you do need at least one .cpp file to pull in all the header files when compiling. Now I know some people would absolutely detest this idea. But I haven't found any convincing downsides of doing this. I can list some advantages: [1] Faster compile times. All header files only get parsed once, because there is only one .cpp file. Also, one header file

Should C++ eliminate header files?

久未见 提交于 2019-11-26 17:59:48
问题 Many languages, such as Java, C#, do not separate declaration from implementation. C# has a concept of partial class, but implementation and declaration still remain in the same file. Why doesn't C++ have the same model? Is it more practical to have header files? I am referring to current and upcoming versions of C++ standard. 回答1: I routinely flip between C# and C++, and the lack of header files in C# is one of my biggest pet peeves. I can look at a header file and learn all I need to know

using namespace std; in a header file

女生的网名这么多〃 提交于 2019-11-26 17:51:10
So, I have the following in a specification file #include <string> #include <fstream> using namespace std: class MyStuff { private: string name; fstream file; // other stuff public: void setName(string); } I also have in the implementation file #include "MyStuff.h" using namespace std; void MyStuff::setName(string name); { name = name } and in the program file I have... #include <iostream> #include <string> using namespace std; void main() { string name; MyStuff Stuff; cout << "Enter Your Name: "; getline(cin, name); Stuff.setName(name); } And I'm gathering that applying "using namespace std;"

Self-sufficient header files in C/C++

依然范特西╮ 提交于 2019-11-26 17:35:56
问题 I recently posted a question asking for what actions would constitute the Zen of C++ . I received excellent answers, but I could not understand one recommendation: Make header files self-sufficient How do you ensure your header files are self-sufficient ? Any other advice or best-practice related to the design and implementation of header files in C/C++ will be welcome. Edit: I found this question which addresses the "Best Practices" part of mine. 回答1: A self sufficient header file is one

How to read a CMake Variable in C++ source code

我的未来我决定 提交于 2019-11-26 17:35:53
I'd like to store the version number of my library in just one place. So I have defined such a variable in the CMake-file: SET(LIBINTERFACE_VERSION 1 CACHE INTEGER "Version of libInterface") With this definition I can generate a version.rc file according to Microsoft's definition, which I compile into the library and afterwards shows up correctly in the properties window of my dll-file. Now I'd like to use this CMake variable in my c++ source code too, but I actually don't get to a working solution. I've tried different things like this: #ifndef VERSION_LIBINTERFACE # define VERSION

How can a C++ header file include implementation?

早过忘川 提交于 2019-11-26 17:27:20
问题 Ok, not a C/C++ expert by any means, but I thought the point of a header file was to declare the functions, then the C/CPP file was to define the implementation. However, reviewing some C++ code tonight, I found this in a class's header file... public: UInt32 GetNumberChannels() const { return _numberChannels; } // <-- Huh?? private: UInt32 _numberChannels; So why is there an implementation in a header? Does it have to do with the const keyword? Does that inline a class method? What exactly