header-files

Code duplication between typedefs and explicit instantiations

白昼怎懂夜的黑 提交于 2019-11-30 15:17:32
tree.h template<typename Functor, char Operator> class binary_operation : public node { // ... unimportant details ... unsigned evaluate() const; void print(std::ostream& os) const; }; typedef binary_operation<std::plus<unsigned>, '+'> addition; typedef binary_operation<std::multiplies<unsigned>, '*'> multiplication; // ... tree.cpp template<typename Functor, char Operator> unsigned binary_operation<Functor, Operator>::evaluate() const { // ... unimportant details ... } template<typename Functor, char Operator> void binary_operation<Functor, Operator>::print(std::ostream& os) const { // ...

Headers include in multiple C files

大城市里の小女人 提交于 2019-11-30 14:39:26
I have two files foo.c and bar.c that I compile separately with gcc -c and then link. Both files need the stdio.h and stdlib.h headers. Do I have to include them in both? Doesn't feel a little redundant? Should I maybe use #ifdef? What's the best practice? Each C file is a different translation unit . In other words, it is an entire separate program , syntactically complete and correct. Thus, each C file must compile independently of any other C file, and must contain every declaration for every identifier it uses, regardless of whether these declarations also appear in other C files. From the

How to see the actual order of include files after preprocessing?

夙愿已清 提交于 2019-11-30 14:04:46
I have one .cpp file that includes a few header files. These header files may include other header files as well. Include guards are in place to prevent including the same file twice. Knowing that each file is only included once. Is there a way to figure out the eventual order in which all headers will be included? I tried gcc -E to get the preprocessor output, but the generated code doesn't seem usable for extracting the information that I want. Can anyone help? Edit The reason why I'm asking is because I need to include my header files in a SWIG interface file in the correct order to avoid

Include .cpp instead of header(.h)

不羁的心 提交于 2019-11-30 12:36:47
问题 There are some cases when we include .cpp file instead of standard header file (.h), for example: #include "example.cpp" instead of #include "example.h" It seems to work but is this safe or should I avoid it? What about the compilation time? 回答1: It's lazy coding. Use header files. Yes they can increase compile time but they mean that you can easily re-implement chunks of your code, or better yet, another developer could at anytime. The header file serves as a template for what your C/C++

How to have CMake show headers-that are not part of any binary target-in the IDE?

眉间皱痕 提交于 2019-11-30 11:51:25
问题 In our workflow, we can have a module A that is composed of several header files, module A not producing any binary (side note: it will obviously be used by other modules, that include some of the headers from module A to produce binaries). A good example would be a header-only library, for which CMake 3 introduces a good support thanks to the notion of INTERFACE library (see this SO answer, and CMake's documentation of the feature). We can make an interface library target out of module A :

Why doesn't C# have header files? Will the namespace take care of everything?

假如想象 提交于 2019-11-30 11:13:55
I'm a novice programmer, can anyone tell clearly about the usage of header files and namespaces in C#? Because in C++ I was using ******.h files to read library functions. And when I saw some sample programs in C# they were missing, Can anyone tell me why? I'm using C# to develop customised tool for a mechanical CAD software, there whenever I use the appropriate function to open the file (CAD file), the compiler is giving me an error stating that the function names which I supply are not available in the context. Here what does meant by context ? When I opened the help file of that CAD

C++ namespace and include

巧了我就是萌 提交于 2019-11-30 10:26:45
问题 Why do we need both using namespace and include directives in C++ programs ? For example, #include <iostream> using namespace std; int main() { cout << "Hello world"; } Why is it not enough to just have #include or just have "using namespace std" and get rid of the other ? (I am think of an analogy with Java, import java.net.* will import import everything from java.net, you don't need to do anything else.) 回答1: In C++ the concepts are separate. This is by design and useful. You can include

What is the difference between header file and namespace?

拈花ヽ惹草 提交于 2019-11-30 06:46:48
I want to know the exact difference between Header file (as in MyHeader.hpp) and a namespace in c++ ? Header files are actual files - stored in the file system, referenced by file name, and #include 'd in other files (at least, in C/C++ or other languages using the M4 macro preprocessor). Header files typically group pieces of code that are all interdependent parts of the same specific item together. For instance, a game might have a header file for all of its graphics rendering. Namespaces, on the other hand, are an element of the programming language - they don't exist as a file system

Why do I see THROW in a C library?

和自甴很熟 提交于 2019-11-30 05:38:26
When I do: less /usr/include/stdio.h (which is only a C library - nothing to do with C++) I see __THROW after quite a few function declarations. Also, comments above a few functions say that 'This function is a possible cancellation point and therefore not marked with __THROW ' What is all this for? throw is meant to be for exception handling...but as far as I know, C doesn't provide any support for it. Please explain. This header is likely shared between the C and C++ compiler for that vendor. Did you look what __THROW is defined as? I suspect something akin to: #ifdef __cplusplus #define _

Xcode - Importing different header file with same name based on Target

≯℡__Kan透↙ 提交于 2019-11-30 05:27:39
I have a project with multiple targets each of which builds a pretty similar versions of the app but with different images assets and plists. For plists/images that's fine but I use the ShareKit and Appirater frameworks which have header files with #defines for their config. For each version I believe need to import a different version of this header file, as the config is different for each app built by each target. So target A has SHConfig.h and target B has a DIFFERENT SHConfig.h I could edit the source for these frameworks to import different headers based on the target but that'd be messy