C++ functions

Can I made some file only with functions,which I call from other programs?
Yes.
Yes? Thank you!!!! HOW? :-)
If you want the function to be loaded at run-time then you're looking for a DLL (That's what a DLL is, a collection of functions that programs can load when they run), or if you want those function to be compiled into the other using executables, a static library.

Look up info on how to create dynamic/static libraries for your operating system.
A simpler answer is: make a .hpp file with declarations of your functions:
1
2
3
//foo.hpp
#include <string>
int useful_function(string x);

Then define them in a .cpp file:
1
2
3
4
5
//foo.cpp
#include <string>
int useful_function(string x){
    //do useful stuff
}

Then #include foo.hpp and when you compile put foo.cpp on your line:
g++ myprogram.cpp foo.cpp -o myprogram
Then you can use the functions you declared.
Topic archived. No new replies allowed.