• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
sfesly
博客园 首页 新随笔 联系 订阅 订阅 管理

2015年12月21日

Why am I getting an error converting a Foo** → const Foo**?
摘要: Because converting Foo** → const Foo** would be invalid and dangerous.C++ allows the (safe) conversion Foo* → Foo const*, but gives an error if you tr... 阅读全文
posted @ 2015-12-21 17:20 sfesly 阅读(218) 评论(0) 推荐(0)
 
The constness of a method should makes sense from outside the object
摘要: C++的encapsulation机制使得我们可以使得一个类的逻辑接口和内部表示有很大的差异,比如下面这个矩形类:class Rectangle{public: int width() const {return x;} int height() const {return y;} ... 阅读全文
posted @ 2015-12-21 16:47 sfesly 阅读(184) 评论(0) 推荐(0)
 
Virtual Friend Function
摘要: 一般而言,友元作为一种紧耦合的设计,被视作类的一部分。一个经典的应用就是关于类的序列化和反序列化。class A{ friend ostream& operator<<(ostream& os, const A& a);private: int i;}ostream& operator<... 阅读全文
posted @ 2015-12-21 13:51 sfesly 阅读(234) 评论(0) 推荐(0)
 
 

公告


博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3