< previous page page_845 next page >

Page 845
(text box continued from previous page)
class TimeType
{
    int hrs;
    int mins;
    int secs;
public:
    void    Set( int, int, int );
    void    Increment();
    void    Write() const;
    Boolean Equal( TimeType ) const;
    Boolean LessThan( TimeType ) const;
};
By default, the variables hrs, mins, and secs are private. The public part extends from the word public to the end of the class declaration.
Even with the private part located first, some programmers use the reserved word private to be as explicit as possible:
class TimeType
{
private:
    int hrs;
    int mins;
    int secs;
public:
    void    Set( int, int, int );
    void    Increment();
    void    Write() const;
    Boolean Equal( TimeType ) const;
    Boolean LessThan( TimeType ) const;
};
Our preference is to locate the public part first so as to focus attention on the public interface and deemphasize the private data representation:
class TimeType
{
public:
    void    Set( int, int, int );
    void    Increment();
    void    Write() const;
    Boolean Equal( TimeType ) const;
    Boolean LessThan( TimeType ) const;
private:
    int hrs;
    int mins;
    int secs;
};

(text box continues on next page)

 
< previous page page_845 next page >