i have a file named functions.h….now i know that it is not wise to define functions in the header files but that is least of my concern as compared to the problem which cropped up…
i defined a function in a functions.h named
void sayhi()
{
cout<<"hi";
}
now i made a lines.h file whose functions were defined in lines.cpp file…in lines.cpp file i included functions.h…and used sayhi(); in the constructor of lines class…then in mymain.cpp(containing int main) i again included functions.h and in the main i called sayhi();
but when i compiled the program it showed an error in mymain.cpp telling that sayhi() has already been defined in lines.obj…can u point out what am i doing wrong??
Well, the solution is to declare the function in functions.h and then define it in functions.cpp, the way nature intended.