c++ - How do I understand about cpp headfiles -


  • why headfiles of main.cpp need include .h headfiles contain declaration instead of implementation?

  • can write class in cpp file including both declaration , implementation , include cpp file main.cpp headfile?

  • how can include headfile not in project?

technically, header file (or other file decide #include) can contains absolutely whole makes complete c++ program.

what happens when compiler (technically, part of compiler package called "c preprocessor") sees #include "somefile.h" in source-code takes file, , "pastes" main file being compiled. "pretend" preprocessor opening headerfile, marking , pasting main file.

the point header files avoid copying , pasting same bit of c++ several source files. example, declaration of class can put header file myclass.h, actual implementation myclass.cpp file, , part of program using myclass need include header.

header files not part of project typically surrounded angle brackets, #include <header.h> include "header.h" other project.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -