novice wrote:
I'm a beginner in C++.
Yesterday i got a doubt, when i was writing a program,
I had to define some Classes and Functions common to
many files. Then I was confused wheather to create a namespace
or a header file. Can you guys please explain me what's the
difference between the two and which is for what.
Use header files to share information among compilation units. Without
it, you need to copy and paste the shared code to compilation units that
need it and every time you change the shared code you need to copy and
paste it to all compilations units using it.
Use namespaces to avoid name clashes. Without it you will need to give
very long and ugly looking names to every function and class and every
time you use this functions or classes you need to type the whole name.
Regards,
Ben