Hello everyone.My name is Icy and i am new to this forum.I have started C++ a while ago and this site has been my main source of information.Ok now my question.
Is it possible to import c++ code from another file and use it in another c++ project.For example,let's say i'm making a big project with many functions in it.What if i wrote some of these functions in separate files and then when i needed to call those functions in my main project file i would use a command to do so.I have tried it by including fstream but it outputs the whole source code of the file i imported.I don't know if i explained what i wanted to know.
You need to:
put the source in a separate file
place the declarations of the symbols defined in that file in a header,
#include that header everywhere you use that symbol
compile all the sources and link them together
When the compiler is looking through files, it's not that intelligent. A "header guard" stops the compiler reading the same header information twice, which would make it throw a fit.
When you chose an identifier for your header guard you have to make sure that it's not used elsewhere, so a longer non-trivial identifier is better. Using the filename helps since is unlikely that you have two files with the same name