i got 2 programmes that use the same function how can i make them use a another file to get the function like in php you know with the include statement will that style work under c++
i got 2 programmes that use the same function how can i make them use a another file to get the function like in php you know with the include statement will that style work under c++
You can create your own header file...
#include YouirFile.h
Your header file would then have:
#include YourFile.cpp
or just #include YourFile.cpp without the .h file (bad practice).
Make sure your file is in an "accessable" directory/folder, or give the full path & filename.
Do you want dynamic or static sharing of code?
"Dynamic sharing" of code would be like DLL's on Windows, or shared libraries on Linux.
"Static sharing" of code would be linking in a library.
gg
lets say first line #include myfile.cpp
and inside it there is a function lets say
do i have to write a prototype some where?Code:int myfunc() { return a*b; }
Don't include .cpp files!
Read this instead.
gg
I'm not completely sure that I've understood the question but...
You could write the function in a textfile called "TextFile" like so...
And then in the source files where functions are listed type...Code:void Add(int a, int b) { int sum(0); sum = a + b; cout<<"The sum is "<<sum<<endl; }
Of course if you do this you need a protoype in both source files where protoypes usually go for functions.Code:#include "TextFile.txt";