Tag Info

Hot answers tagged

37

It is because the C++ compiler must know the actual size of the class in order to allocate the right amount of memory at instantiation. And the size includes all members, also private ones. One way to avoid this is using the Pimpl idiom, explained by Herb Sutter in his Guru of the Week series #24 and #28. Update Indeed, this (or more generally, the header ...


25

My view... Document how to use the function in the header file, or more accurately close to the declaration. Document how the function works (if it's not obvious from the code) in the source file, or more accurately, close to the definition. For the birds-eye thing in the header, you don't necessarily need the documentation that close - you can document ...


21

These answers were extracted from the book Patents, Copyright and Trademark, highly recommended. If you plan to buy one, notice that there's a newer edition than that I have. Does a single date imply that the author claims copyright of the file from that date until eternity? "The copyright lasts for the life of the author plus 70 years. However, under ...


18

C and C++ behave very much the same in this regard -- you can have inline functions in headers. In C++, any method whose body is inside the class definition is implicitly inline. If you want to do the same in C, declare the functions static inline.


13

In C, if you define a function in a header file, then that function will appear in each module that is compiled that includes that header file, and a public symbol will be exported for the function. So if function additup is defined in header.h, and foo.c and bar.c both include header.h, then foo.o and bar.o will both include copies of additup. When you go ...


9

What to put in headers: The minimal set of #include statements that are needed to make the header compilable when the header is included in some source file. Preprocessor symbol definitions of things that need to be shared and that can only accomplished via the preprocessor. Even in C, preprocessor symbols are best kept to a minimum. Forward declarations ...


8

If you're going to use a tool such as Doxygen (note in the first example, that really looks like a Doxygen comment because it starts with /**) then it doesn't really matter - Doxygen will look through your header and source files and find all the comments to generate the documentation. However, I'd be more inclined to put the documentation comments in the ...


8

While the second version is easier to write, it is mixing interface with implementation. Source files which include header files need to be recompiled everytime the header files are changed. In the first version you'd change the header file only if you need to change the interface. In the second version you'd change the header file if you need to change the ...


8

"All problems in computer science can be solved by another level of indirection." (quote source) In one of my past projects, we once got such kind of requirement. It has been solved once and forever by inserting a "copyright placeholder" into source code stored under version control: // %%COPYRIGHT PLACEHOLDER%% Whenever any change in that text was ...


8

While you can include .cpp files as you mentioned, this is a bad idea. As you mentioned, declarations belong in header files. These cause no problems when included in multiple compilation units because they do not include implementations. Including a the definition of a function or class member multiple times will normally cause a problem (but not always) ...


7

In short; The header file defines the API for a module. It's a contract listing which methods a third party can call. The module can be considered a black box to third parties. The implementation implements the module. It is the inside of the black box. As a developer of a module you have to write this, but as a user of a third party module you ...


7

The class definition needs to be sufficient for the compiler to produce an identical layout in memory wherever you've used an object of the class. For example, given something like: class X { int a; public: int b; }; The compiler will typically have a at offset 0, and b at offset 4. If the compiler saw this as just: class X { public: int b; ...


6

http://stackoverflow.com/questions/1305947/why-does-c-need-a-separate-header-file http://stackoverflow.com/questions/333889/in-c-why-have-header-files-and-cpp-files http://stackoverflow.com/questions/752793/should-c-eliminate-header-files ...and more


6

Probably somebody did that as an example of a cache expires a long time ago and then everybody copied it. Interestingly it's often expressed as "Mon, 26 July 1997", but the actual date occurred on a Saturday. It's not that interesting in terms of UTC seconds (seconds since 1970) since it is 869893200. Maybe it's just an example of CTRL-C/CTRL-V coding?


6

Read more on the role of the C and C++ preprocessor, which is conceptually the first "phase" of the C or C++ compiler (historically it was a separate program /lib/cpp; now, for performance reasons it is integrated inside the compiler proper cc1 or cc1plus). Read in particular the documentation of the GNU cpp preprocessor. So in practice the compiler ...


5

Some source control systems may not add the header files to source control if they are also not added to the solution file. Your mileage may vary, depending on the source control you use and how you use it.


5

I had proposed a quite similar approach here: http://stackoverflow.com/questions/4248831/shared-config-file-between-php-and-c/4248881#4248881 for a similar issue. I would suggest to write a small script that generates code for C++ and JavaScript, with the configuration you want to have common. You can also use two templates in a template library, that you ...


4

The main reason for a header is to be able to #include it in some other file, so you can use the functions in one file from that other file. The header includes (only) enough to be able to use the functions, not the functions themselves, so (we hope) compiling it is considerably faster. Maintaining the two separately most results from nobody ever having ...


4

Objective-C (and and its C++ counterpart, Objective-C++) can #include C (C or C++) header files as well as #import Objective-C header files. That pairs are even used is by convention. In additon, ASP, Perl, Python, Pascal, and, since the file extension used for its includes doesn't have to follow a standard, PHP. Edit: Most assembler source code also use ...


4

Does a single date imply that the author claims copyright of the file from that date until eternity? The date is usually when the file was created (i.e.: first copyright). If the file was changed, then the date range (or list of years) covers the period of changes until the last change (last copyright). Copyright is time-limited, so the timestamp is ...


4

Mainly just to give you single click editing. The solution explorer doesn't effect the dependancy of the build/compiler. edit. Sometime's it's necessary if you need to 'compile' a header eg. a COM .idl or some Qt moc header file.


4

I wouldn't recommend that you make non-standard use of a standard HTTP header. Primarily because it can be misleading to other developers that know how the Authoriziation header is meant to be used in HTTP authentication, but also to avoid any potential issues with other parts of your stack having conflicting awareness of the same request header. Whatever ...


4

This answer looks at header files from a language design perspective. My point is not that you shouldn't use headers in your C or C++ programs – headers are required by these languages. Instead, this answer is an argument that you shouldn't design new languages that use header files. Header files are bad language design, at least from a modern ...


3

We solved this problem (about 25 years ago) by creating a bunch of #defines (e.g. public, private, etc., that resolved to <nothing>) that could be used in the source file and were scanned by an awk script (horrors!) to auto-generate the .h files. This mean that all of the comments lived in the source and were copied (when appropriate) into the generated ...


3

I did it the second way back in '93-95. Took a few minutes to recompile a small app with 5-10 functions/files (on that same 486 PC .. and no, I didn't know about classes either, I was just 14-15 years old and there was no internet). So, what you teach beginners and what you use professionally is vastly different techniques, especially in C++. I think the ...


3

F#: It optionally allows a .fsi file to declare the symbols like C headers. See http://en.wikibooks.org/wiki/F_Sharp_Programming/Modules_and_Namespaces#Module_Signatures


3

There are most likely several reasons. While private members can't be accessed by most other classes, they can still be accessed by friend classes. So at least in this case they may be needed in the header, so the friend class can see they exist. The recompilation of dependent files may depend on your include structure. Including the .h files in a .cpp file ...


3

Only thing I could find was the release of Mac OS 8. Not related to CSS release dates, HTML, XML, PHP, Javascript, Internet Explorer, Nescape Navigator, Apache Foundation, MySQL, or anything else relevant I could wrack my brain for. I suspect it's probably someone's kid's birthday or anniversary or something. In short, it's a coincidence.


3

There are no serious issue in transferring access token over http headers because transferred data is encrypted when SSL is used, means it can be understand only by particular client which made that request and server who responses for the request, in between there are no chances to understand the data by any third party. Other thing is access token are ...



Only top voted, non community-wiki answers of a minimum length are eligible