Skip to content

Instantly share code, notes, and snippets.

@paullewallencom
Last active July 31, 2018 18:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paullewallencom/1101471f239af098b3d61f85c85dd3b8 to your computer and use it in GitHub Desktop.
Save paullewallencom/1101471f239af098b3d61f85c85dd3b8 to your computer and use it in GitHub Desktop.
C++ Simulates Int Memory
#include "IntCell.h"
IntCell::IntCell( int initialValue ) : storedValue{ initialValue }
{
}
int IntCell::read( ) const
{
return storedValue;
}
void IntCell::write( int x )
{
storedValue = x;
}
#ifndef IntCell_H
#define IntCell_H
/**
* A class for simulating an integer memory cell.
*/
class IntCell
{
public:
explicit IntCell( int initialValue = 0 );
int read( ) const;
void write( int x );
private:
int storedValue;
};
#endif
#include <iostream>
#include "IntCell.h"
using namespace std;
int main( )
{
IntCell m; // Or, IntCell m( 0 ); but not IntCell m( );
m.write( 5 );
cout << "Cell contents: " << m.read( ) << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment