#pragma once
class IntCell{
public:
explicit IntCell(int initialValue = 0);
int read() const;
void write(int x);
private:
int storedValue;
};
//IntCell.h
#include "pch.h"
#include "IntCell.h"
IntCell::IntCell(int initialValue) : storedValue{ initialValue }
{}
int IntCell::read() const
{
return storedValue;
}
void IntCell::write(int x)
{
storedValue = x;
}
- explicit 禁止隐式转换
- (int initialValue = 0) 初始值0
- : storedValue{ initialValue } 列表初始化
- int IntCell::read() const accessor 访问函数,函数中不能修改值
- void IntCell::write(int x) mutator 修改函数