c++ header functions

can someone give me an example of a header file and its cpp file with multiple functions and classes on the header?
Can we initialize header functions on different cpp files? What if two or more .cpp files has initialize the same functions? Or does the compiler looks for the function initiailizor(or whatever u call it) on its <ClassNameonHeader>.cpp?
> function initiailizor(or whatever u call it)
I have no idea what you are talking about.

I have no idea what you are talking about.


what i meant by that is, the compiler will automatically searches a cpp file for the body of the function that u declared at the header file

EDIT:: will it search on the <NameOfClassInHeader>.cpp or will it search on any cpp files that has #include "<headerName>.h"
Last edited on
You compile the sources into object files (you can see what symbols are defined with `nm')
Later you link them into the executable (resolve the function calls)

If two cpp define the same function, and you try to link them together then it will give you the
`multiple definition of ...' error

The name of the files is unimportant.
thats what i just thought...just wanna confirm it
thanks @ne555
anyway, i have another question
is there a datatype that can accept all datatypes for "cout" purposes

for example
1
2
3
4
void popUp(string msg)
{
    cout << msg << endl;
}


im hoping i can find a datatype to replace in <string> so whatever i send to pop() it will cout it
like pop(DWORDtype) / pop(intType) etc....

EDIT:: nvm i got it now, i just overload the function and place (int msg) as the parameter of the second function, dont know if it will work on every type thought
Last edited on
Make it a template
1
2
3
4
template <class T>
void popUp( const T &item ){
   std::cout << item << std::endl;
}
oh cool, i have no idea what was template awhile ago
but now that i googled it, its pretty awesome. i will implement it right away
thanks again @ne555, i would hug u but cant
Topic archived. No new replies allowed.