95 .cpp is the recommended extension for C++ as far as I know. Some people even recommend using .hpp for C++ headers, just to differentiate from C. Although the compiler doesn't care what you do, it's personal preference.
I have some template code that I would prefer to have stored in a CPP file instead of inline in the header. I know this can be done as long as you know which template types will be used. For exam...
itoa will be faster than the stream equivalent. There are also ways of re-using the string buffer with the itoa method (avoiding heap allocations if you are frequently generating strings. e.g. for some rapidly updating numerical output). Alternatively you can generate a custom streambuf to reduce some of the allocation overhead etc. Constructing the stream in the first place is also not a low ...
20 Put as many includes in your cpp as possible and only the ones that are needed by the hpp file in the hpp. I believe this will help to speed up compilation, as hpp files will be cross-referenced less. Also consider using forward declarations in your hpp file to further reduce the include dependency chain.
In my project code, I found that someone used #ifdef and #if in code. I would like to know what does purpose for using them? As my knowledge, it said to the preprocessor will not do anything inside...
Yes, this form of initialization is supported by all C++ compilers. It is a part of C++ language. In fact, it is an idiom that came to C++ from C language. In C language = { 0 } is an idiomatic universal zero-initializer. This is also almost the case in C++. Since this initalizer is universal, for bool array you don't really need a different "syntax". 0 works as an initializer for bool type as ...
I want to use the PI constant and trigonometric functions in some C++ program. I get the trigonometric functions with include <math.h>. However, there doesn't seem to be a definition for PI i...
There are also .h files that contain classes and their function definitions. Until now the program was compiled using the command g++ main.cpp. Now that I've separated the classes to .h and .cpp files do I need to use a makefile or can I still use the g++ main.cpp command?