Subj : Re: "File Scope" objects To : comp.programming,comp.software-eng From : Phlip Date : Thu Aug 18 2005 03:23 pm Gerry Quinn says... > >> For C++, many classes should live only inside a .cpp file. (Put another >> way, >> many C++ newbies think that all class definitions only belong in header >> files, which is wrong.) > > You want to define class B in the implementation file of class A, i.e. > "a.cpp". > > But suppose class B is written as normal, i.e. "b.h" and "b.cpp", but > "b.h" is included only in "a.cpp". > > You won't be looking at "b.h" anyway except by way of finding an > include in "a.cpp". So why worry about it? Because #include "b.h" is a compilable comment tempting your colleagues "b.h" is designed to be reused. It is not. I am aware there are other ways to comment the situation, and there are other technical reasons to #include "b.h". > Doing thing the normal way There's a difference between a normalized way and "the way we have always done it". > gives effectively the same result, and stops classes contaminating each > others files. > > Only if you are sure B will be useless without A do you gain anything - > and even then, you have a longer, more unwieldy file, in which > functions of two classes have to be kept in order. Or you use > something like MSVC that obscures the details of file structure by > creating hyperlinks to functions, in which case there is also no > benefit. In some situations long .cpp files speed up compiling and linking. There are so many physical issues involved that we cannot promote the idea "put the private class B entirely inside A's implementation file" to the level of a "guideline". It's still a helpful suggestion, and a way to debunk the newbie that all classes belong in .h files. -- Phlip http://www.greencheese.org/ZeekLand <-- NOT a blog!!! .