| Version 1.9 Build 803
|
|
Next: Templates
Up: Code Organization
Previous: Modules
It is sometimes appropriate to write
global functions to act on class objects, rather than creating
class member functions. As a general rule, you should do this if
there is no class object state preserved from one function call to the next,
and all of the information about the class object/s can be obtained
from the public interface. However, for reasons of namespace
management it
is often advised if there exists a strong binding between the class and the
global function, to make the global function a static member of the class; or
use the namespace keyword.
There are two places where global functions
may be declared and defined: as part of the .cc and .h files
of the class they are most closely associated with, or in their own, separate
.cc and .h files. Use these criteria to decide:
- If there is a large conceptual distance between the functions and
the class, then it is probably best to use separate files.
- If there are a large number of related global functions, use
separate files.
- If the functions are templated, using separate files (at least separate
implementation files) will reduce
template instantiation dependencies.
Next: Templates
Up: Code Organization
Previous: Modules
Contents
Index
Please send questions or comments about AIPS++ to aips2-request@nrao.edu.
Copyright © 1995-2000 Associated Universities Inc.,
Washington, D.C.
Return to AIPS++ Home Page
2004-08-30