J
jk
Newbe Question ...
I have read "C++ the complete reference" by Herbert Schildt and
understood (most) of it
but have a couple of queries.
(1) In real world applications the code is split into .h and .cpp
files not all just one file. The .h files having the class definitions
and prototypes and the .cpp having the methods. OK so when i #include
a file in my program I am including the headers or .h file. Why is
there this split - why not just have one file and include that ?
(2) In real world programs I have found the following construct in
class constructors to set a value to a variable:
in .h file ...
class test {
....
private:
int mHighestMenuId;
}
in .cpp file ...
test::test( )
:mHighestMenuId(6)
{
....
ie using the dependent classes initialise values section of the
constructor to initialise the variable to 6. Why do it this way ? Is
there any advantage over just
setting mHighestMenuId = 6; in the constructor ?
Dave
I have read "C++ the complete reference" by Herbert Schildt and
understood (most) of it
(1) In real world applications the code is split into .h and .cpp
files not all just one file. The .h files having the class definitions
and prototypes and the .cpp having the methods. OK so when i #include
a file in my program I am including the headers or .h file. Why is
there this split - why not just have one file and include that ?
(2) In real world programs I have found the following construct in
class constructors to set a value to a variable:
in .h file ...
class test {
....
private:
int mHighestMenuId;
}
in .cpp file ...
test::test( )
:mHighestMenuId(6)
{
....
ie using the dependent classes initialise values section of the
constructor to initialise the variable to 6. Why do it this way ? Is
there any advantage over just
setting mHighestMenuId = 6; in the constructor ?
Dave