Skip to Content
Navigating C++ and Object-Oriented Design
book

Navigating C++ and Object-Oriented Design

by Paul Anderson, Gail Anderson
October 1997
Intermediate to advanced
800 pages
20h 48m
English
Pearson
Content preview from Navigating C++ and Object-Oriented Design

5.11. Putting It All Together

Namespaces and Classes

Let's see how to use namespaces (page 132) with classes. The following header file defines a namespace for our Roman class (see Listing 4.9 on page 201).

Listing 5.13. Class Roman interface with namespaces
#ifndef ROMANH
#define ROMANH
// Roman.h - Roman class

namespace Anderson_Software_Group {
   const int Roman_max = 20;
   class Roman {
   private:
      int value;                    // decimal value
      char s[Roman_max];            // Roman String
      void convert_Roman();         // convert to Roman string
   public:
    // Constructors
      Roman(int n = 1) { value = n; convert_Roman(); }
    // Member Functions
      const char *getroman() const { return s; }
      int getnum() const { return value; }
   };
}
#endif

Namespace Anderson_Software_Group includes a constant ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Exploring C++20: The Programmer's Introduction to C++

Exploring C++20: The Programmer's Introduction to C++

Ray Lischner

Publisher Resources

ISBN: 0135327482Purchase book