533 pdfsam Cplusplus Primer Plus 4th Edition

This document was created by an unregistered ChmMagic, please go to http://www.bisenter.com to register it. Thanks stat...

0 downloads 6 Views 2KB Size
This document was created by an unregistered ChmMagic, please go to http://www.bisenter.com to register it. Thanks

static int counts; // static storage, internal linkage int other(); int main() { } int other() { } The intent of the standard is that you should do this instead:

namespace { int counts; // static storage, internal linkage } int other(); int main() { } int other() { }

A Namespace Example Let's take a look at a multifile example that demonstrates some of the namespace features. The first file is a header file that contains some items normally found in header files—constants, structure definitions, and function prototypes. In this case the items are placed in two namespaces. The first namespace, called pers, contains a definition of a

Person structure, plus prototypes for a function that fills a structure with a person's name and a function that displays the structure contents. The second namespace, called debts , defines a structure for storing the name of a person and the amount of money owed to that person. This structure uses the Person structure, so, the debts namespace has a using-directive to make the names in the pers available in the debts namespace. The

debts namespace also contains some prototypes. Listing 9.9 shows this header file.