O'Reilly logo

SAMS Teach Yourself C++ in 10 Minutes SECOND EDITION by Jesse Liberty

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Making a Library Changes Your Names

Remember the function Initialize(), which was used to prepare cin for throwing exceptions? What if you moved error handling out to a module of its own, and some other library or main program wanted to use that common name? This could be a problem.

You have already seen a way to deal with this possibility: namespaces. That's the solution iostream uses and it will work perfectly for this situation.

The form of a namespace declaration is

namespace namespacename
{
   statements
} ;

Listing 8.3 is the new header file.

Listing 8.3. Header for ErrorHandlingModule
 1: #ifndef ErrorHandlingModuleH 2: #define ErrorHandlingModuleH 3: *4: namespace SAMSErrorHandling *5: { 6: void Initialize(void); 7: int HandleNotANumberError(void); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required