Headers and Sources in C++
hi,
If I have any C + + source code from the Internet to view, then there's a *. cpp and *. h file with the same name.Traditionally, it is so that in the header files, the prototypes of the functions and features and elements in the same source files, the declarations are correct?Suppose that all files belong to a project (in my Dev-Cpp), the cpp file, where the main () function is available, but all must include the header files (# include "xyz.h")? But what with the same name *. cpp files.I did as an abstract class in a header "abstract.h" should be a class SubAbstract that inherits the abstract class and what in "subabstract.h" should be, the declaration of the element functions come in "subabstract.cpp "and then somewhere in the" main.cpp ".can any one give me the explanation?Thanks in advance for your help.
Re: Headers and Sources in C++
It normally uses headers in this framework
Code:
# ifndef EXAMPLE_HEADER_H
# define EXAMPLE_HEADER_H
/ / ... Header Code ...
# endif
But here EXAMPLE_HEADER_H for a clear definition per header.By this will prevent the header in the same translation unit is inserted twice, which is inevitably would lead to problems.
Re: Headers and Sources in C++
The compiler processes all source files from a project individually. it is not necessarily know how a called function is implemented (definition) is, he must be the only correct way in which they are familiar call. Therefore, the "notice" (declaration) in a header file included. The compiled files,are not really executable, there is usually still a lot of placeholder for function calls and variables from other sources. From the compiled files is an executable file, then the linker compound.
Re: Headers and Sources in C++
Do you mean any constants? If yes then it should be included in the header / source file in which you use this. Do you have the header definition, as described Code has included them in the header file.