mirror of
https://gitlab.com/fbb-git/cppannotations
synced 2024-11-16 07:48:44 +01:00
777b182edd
This allowed me to standardize the sourcetar and sf/* scripts: the base directory (containing ./git) is now empty, except for maintenance scripts, while the source files and build scripts of the annotations are stored in a subdirectory of their own.
31 lines
1.7 KiB
Text
31 lines
1.7 KiB
Text
In the previous chapters we provided examples of classes where each object
|
|
had its own set of data members data. Each of the class's
|
|
member functions could access any member of any object of its class.
|
|
|
|
In some situations it may be desirable to define
|
|
emi(common data fields), that may be accessed by em(all) objects of the
|
|
class. For example, the name of the startup directory, used by a program that
|
|
recursively scans the directory tree of a disk. A second example is a variable
|
|
that indicates whether some specific initialization has occurred. In that case
|
|
the object that was constructed first would perform the initialization and
|
|
would set the flag to `done'.
|
|
|
|
Such situations are also encountered in bf(C), where several functions need to
|
|
access the same variable. A common solution in bf(C) is to define all these
|
|
functions in one source file and to define the variable ti(static): the
|
|
variable name is invisible outside the scope of the source file. This approach
|
|
is quite valid, but violates our philosophy of using only one function per
|
|
source file. Another bf(C)-solution is to give the variable in question an
|
|
unusual name, e.g., tt(_6uldv8), hoping that other program parts won't use
|
|
this name by accident. Neither the first, nor the second legacy bf(C) solution
|
|
is elegant.
|
|
|
|
bf(C++) solves the problem by defining ti(static members): data and functions,
|
|
common to all objects of a class and (when defined in the private section)
|
|
inaccessible outside of the class. These static members are this chapter's
|
|
topic.
|
|
|
|
Static members cannot be defined as hi(virtual: vs static) virtual
|
|
functions. A virtual member function is an ordinary member in that it has a
|
|
ti(this) pointer. As static member functions have no tt(this) pointer, they
|
|
cannot be declared virtual.
|