How to use C++
Nov. 12th, 2010 10:06 amHow To Use C++
- Real Men use class heirarchies.
- Real Programmers use templates and generics.
- Loonies write the entire program as a cpp macro expansion
- Munchkins use Microsoft wizards and Visual Basic
no subject
Date: 2010-11-12 07:01 pm (UTC)no subject
Date: 2010-11-12 07:03 pm (UTC)no subject
Date: 2010-11-14 10:33 pm (UTC)no subject
Date: 2010-11-12 08:04 pm (UTC)no subject
Date: 2010-11-12 08:19 pm (UTC)no subject
Date: 2010-11-13 04:53 pm (UTC)no subject
Date: 2010-11-14 10:49 pm (UTC)[Oh … turns out that there's an easy solution to the "template code-bloat problem". Say you normally have "TClass.h" and "TClass.tcc", the header and definition of a class called [duh] TClass. Here's what you do:
(A) Move "TClass.tcc" into a "details" subdirectory.
(B) Create a "TClass.cc" file, containing a forward declaration for every template-instantiation you intend to support. It should [obviously] '#include "details/TClass.tcc"'.
(C) Optionally create a "TClass_fwd.h" header that creates typedefs for your supported template-instantiations of TClass.
(D) Link any binary or library that uses one of those supported template-instantiations with "TClass.o".
I use this technique all of the time. Works like a charm.]
no subject
Date: 2010-11-15 12:31 am (UTC)no subject
Date: 2010-11-15 04:57 pm (UTC)Current C++ language style recommends putting the implementation of template (member) functions in a file named *.tcc. Another style recommendation is putting headers and *.tcc files that Have No User-Servicable Parts in a subdirectory named "details" (and, often, in a sub-namespace called "details", as well).
As for the hidden feature: Once you instantiate a C++ template class, it has external linkage. Template functions have external linkage if they're namespace members. Therefore, you only need to instantiate the template once, in one translation unit, then link to that translation unit to your heart's content. Just like for a non-template C++ class.
no subject
Date: 2010-11-15 03:04 pm (UTC)What the heck is an operating system?
:)