programming-examples/c++/Others/Fig01_06.cpp - IntCell class with a few extras, with a test program.cpp

30 lines
731 B
C++
Raw Normal View History

2019-11-15 12:59:38 +01:00
Fig01_06.cpp - IntCell class with a few extras, with a test program
#include <iostream.h>
/**
* A class for simulating an integer memory cell.
*/
class IntCell
{
public:
/* 1*/ explicit IntCell( int initialValue = 0 )
/* 2*/ : storedValue( initialValue ) { }
/* 3*/ int read( ) const
/* 4*/ { return storedValue; }
/* 5*/ void write( int x )
/* 6*/ { storedValue = x; }
private:
/* 7*/ int storedValue;
};
int main( )
{
IntCell m;
m.write( 5 );
cout << "Cell contents: " << m.read( ) << endl;
return 0;
}