When a file is generated with the hidden data flag set, Chic replaces
all the private variables of each class in the file with a single
object that takes care of constructing and copying the private
variables. The motivation behind this is to enable you to add, modify
or remove private variables without changing the memory layout of the
class, and thus not have to recompile clients of that class. The
technique is sometimes called an implementation bridge or a "pimpl".
A small example
When we generate compile files with hidden data from the
static double defaultBeat = 0.75;
we obtain the header
friend class Song_Data;
The hidden class is declared as a nested class and made friend since
it has to access
defaultBeat. Chic also added an
out-of-line destructor as there was none in the class.
Hidden is a template that comes with Chic that takes care
of construction, destruction and copying.
Song_Data is a
class especially created for
Song by Chic. Its
definition is put in the cc-file:
double Song::defaultBeat = 0.75;
Remember that a
struct is the same as a
class except that the default access is public instead of
We use 'q' to denote the name of instance. In case you have to edit
the compile files a one letter variable makes the code quite a lot
There are several restrictions on which classes that can have hidden
You may also consult the faq
for some common issues related to hidden data.
Class templates may not have hidden data.
Inline functions and template functions may not access private
The class may not have an explicitly declared inline constructor
The hidden instance is initialized as the last variable. That
implies for example that public or protected variables may not be
initialized with private variables.
A maximum of 10 constructor arguments can be used.
Care must be taken in custom constructors, assignment operators
The replacement is crude in that it only adds "q->" to all id's with
the name of a private variable in the function bodies. If, for
example, a function declares a variable that hides a private variable,
the replacement will be incorrect and the cc-file will fail to