"Blue Ocean" <ag***********@ gmail.com> wrote in message
news:af******** *************** ***@posting.goo gle.com...
If that is right, let me extend the question a little. Should I
declare private methods in the .h file? Or should I declare them in
the .c file?
In Java, you'll often find private methods, and especially static private
methods, which in C++ are best implemented as non-member utility functions
within the .cpp file.
C and C++ are abit archaic in that they use this subdivision between a
header and a source file, which is an artefact from the way the compilers
work. Java avoids this problem because the equivalent of a header is
generated by the compiler automatically, in a binary form.
The only benefit of headers is that they give you more control regarding
what will be seen by a user of a library. But it is also a burden...
A rule of thumb in C/C++ is that you keep as little information as possible
outside of the headers.
You therefore try to only put in a .h file what has to be accessible to the
users -- the exception being private members of a class, which are not used
from the outside, but need to be declared within a class definition ( class
A { /*here*/ }; ).
Sometimes, putting less information in a header requires specific
workarounds, such as the "pimpl" idiom or the use of abstract base classes.
hth,
Ivan
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- e-mail contact form
Brainbench MVP for C++ <>
http://www.brainbench.com