Vladimir "Dair" Lebedev-Schmidthof (dair_spb) wrote,
Vladimir "Dair" Lebedev-Schmidthof
dair_spb

Безопасная ЖЖ-колбаса по-программистски

11
template< class T >
class Incrementor {
  public:
    Incrementor( const T& beginning );
    const T& next();
  protected:
    virtual void increment();
    T value;
};

template< class T >
Incrementor< T >::Incrementor( const T& beginning )
  : value( beginning )
{
}

template< class T >
const T& Incrementor< T >::next() {
  increment();
  return value;
}

template< class T >
void Incrementor< T >::increment() {
  ++value;
}

/* *** */

Incrementor< int > inc( i );
i = inc.next();

Subscribe

  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 3 comments