|
Prev: basic_stringstream memory management
Next: std::deque typically faster then std::list for push_back(), front(), pop_front()?
From: Montezuma's Daughter on 8 Jan 2008 22:55 I was wondering why h file is needed? I heard it is because in h file the compiler discover what memory is needed for allocation. is that true? thank -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Rune Allnor on 9 Jan 2008 22:07
On 9 Jan, 16:55, "Montezuma's Daughter" <Urania.m...(a)gmail.com> wrote: > I was wondering why h file is needed? I don't know how releveant this is these days, but once upon a time the smallest building block of a static library was what was contained in a 'compilation unit'. There may be other types of compilation units, but I only know of source files. So if you had a large library, like LAPACK which defines all sorts of operations on numerical matrices, it used to make sense to separate the source code into one source file per function. All that has to do with LU decompositions in one source file, singular value decompositions in another, and so on. You can think of such functions as methods in a MatrixClass. The reason for doing things this way was that one wanted to link in only the functionality in the library that was actually used by a program, and not the whole library all the time. In this scenario a separate .h file is very useful as one has exactly one place to look up (and mantain) interface information. These days a C++ library is more and more likely to consist of some sort of template framework, which can only be implemented in .h files. Rune -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] |