user3196284
user3196284

Reputation:

Python has modules, what does c++ have?

Coming from programming in python, I am familiar with modules. What is the equivalent in c++?

Upvotes: 1

Views: 1099

Answers (1)

Seb Maire
Seb Maire

Reputation: 130

The concept in c++ is more complicated than it is with python, from what I remember of python, a module will work without having to take care of the architecture the module was developed.

In C++ (as in C) you have the build process (compile, link) which is important to know when developping with these languages.

In C/C++ you have libraries and header files. To make it simple the header shows the interface of the library (which contains the real compiled code). The thing here is that as libraries are compiled, you will need a different version depending on architecture and the compiler you are using. A Mingw built library won't be compliant with MSVC compiler.

Namespaces can be thought as modules but not in the same way as we call python modules. In C++ namespaces just allow you to "concat" a prefix to what there is in the namespace to avoid names collision (rough example here, the real mechanism behind isn't just concat) and to order the code logically. You cannot just include a namespace as you import a module in python.

I advise you look a tutorial on how the C/C++ build process work, that will explain in detail what are headers, what are libraries and how to use them ;)

Upvotes: 1

Related Questions