板凳——————————————————c++(32)

//2020年05月23日 20时48分46秒
//professional c++ 4th edition p325
#include
#include
#include
#include <string_view>
#include
#include
using namespace std::rel_ops;
//虽然类中只重载了==和<两个关系操作符,但使用命名空间rel_ops后便可以得到6个。

class SpreadsheetCell{
public:
SpreadsheetCell() = default;
SpreadsheetCell(double initialValue);
explicit SpreadsheetCell(std::string_view initialValue);
void set(double inValue);
void set(std::string_view inString);
double getValue() const { mNumAccesses++; return mValue; }
std::string getString() const { mNumAccesses++; return doubleToString(mValue); }
static std::string doubleToString(double inValue);
static double stringToDouble(std::string_view inString);

     SpreadsheetCell& operator+=(const SpreadsheetCell& rhs);
     SpreadsheetCell& operator-=(const SpreadsheetCell& rhs);
     SpreadsheetCell& operator*=(const SpreadsheetCell& rhs);
     SpreadsheetCell& operator/=(const SpreadsheetCell& rhs);
     //p325
     SpreadsheetCell operator-() const;
     SpreadsheetCell& operator++();   // prefix
     SpreadsheetCell operator++(int); // postfix
     SpreadsheetCell& operator--();   // prefix 
     SpreadsheetCell operator--(int); // postfix
private:
     double mValue = 0;
     mutable size_t mNumAccesses = 0;

};
//p327
std::ostream& operator<<(std::ostream& ostr, const SpreadsheetCell& cell);
std::istream& operator>>(std::istream& istr, SpreadsheetCell& cell);

SpreadsheetCell::SpreadsheetCell(double initialValue)
mValue(initialValue){
}
SpreadsheetCell::SpreadsheetCell(std::string_view initialValue)
mValue(stringToDouble (initialValue)){
}

void SpreadsheetCell::set(double inValue)
{
mValue = inValue;
}

void SpreadsheetCell::set(std::string_view inString){
mValue = stringToDouble(inString);
}

std::string SpreadsheetCell::doubleToString(double inValue){
return std::__cxx11::to_string(inValue);
}

double SpreadsheetCell::stringToDouble(std::str

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值