Getting Started Documentation Glish Learn More Programming Contact Us
Version 1.9 Build 803
News FAQ
Search Home


next up previous contents index
Next: Templates Up: Code Organization Previous: Modules

Global Functions

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:
  1. If there is a large conceptual distance between the functions and the class, then it is probably best to use separate files.
  2. If there are a large number of related global functions, use separate files.
  3. If the functions are templated, using separate files (at least separate implementation files) will reduce template instantiation dependencies.

next up previous contents index
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