- Header Files
- .cc and . CPP extension are same
Modules
C++ itself doesn’t have a built-in module system like some other programming languages, including JavaScript with Nodejs. However, in C++, you can use external libraries and packages to achieve similar functionality. These libraries often come in the form of header files and precompiled binary files that you can include in your C++ projects.
Here are a few common approaches in C++ for including external functionality:
-
Header Files: Many C++ libraries provide header files that contain declarations of classes, functions, and variables. These headers are included in your source code to make use of the library’s functionality. You usually need to link your code with the library’s compiled binary to actually use the functions and classes.
-
Dynamic Link Libraries (DLLs) and Shared Libraries: In some cases, libraries are distributed as dynamic link libraries (DLLs) on Windows or shared libraries on Unix-like systems. These are precompiled binary files that your program links to at runtime. They contain the compiled code of the library’s functions.
-
Static Libraries: Static libraries are compiled versions of the library’s code that are included directly into your program’s binary at compile time. This means your executable file contains the library code, which can result in a larger binary size.
-
Package Managers: Some programming communities, like the C++ ecosystem, have package managers that help you download and manage external libraries. Examples include Conan, vcpkg, and CMake’s FetchContent.
While C++ doesn’t have a built-in module system like JavaScript’s import and require in Node.js, you can achieve modular programming by dividing your code into separate header and source files. Libraries and external code can be included using #include directives. Modern C++ standards also introduced the <module> feature, which allows for more modular code organization, but it’s not as widely adopted as in some other languages.
Keep in mind that C++ development often involves a bit more manual effort in terms of managing dependencies and linking libraries compared to some other ecosystems.