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

2015年12月23日

C++11 不抛异常的new operator
摘要: 在google cpp style guide里面明确指出:we don't use exceptionsC++11的noexcept关键字为这种选择提供了便利。C++11以前,提及malloc和new的区别,总是会强调由malloc返回的指针需要检查是不是null,因为空间分配可能失败,而由new... 阅读全文
posted @ 2015-12-23 16:09 sfesly 阅读(2402) 评论(0) 推荐(0)
 
In p = new Fred(), does the Fred memory “leak” if the Fred constructor throws an exception?
摘要: No.If an exception occurs during the Fred constructor of p = new Fred(), the C++ language guarantees that the memory sizeof(Fred) bytes that were allo... 阅读全文
posted @ 2015-12-23 14:58 sfesly 阅读(158) 评论(0) 推荐(0)
 
 

2015年12月22日

method chaining
摘要: 经常写Java的话,可能比较熟悉下面这种函数调用方式 object.method1().method2()术语叫所谓的method chaining,在c++里面,为了支持这种调用格式,你必须保障函数以引用类型返回*this 阅读全文
posted @ 2015-12-22 10:31 sfesly 阅读(229) 评论(0) 推荐(0)
 
C++中的运算符重载
摘要: 运算符重载给c++提供了很强大的功能,使得我们可以将一个类设计得跟内置类型差不多了。但是运算符这种东西最大的问题就是,看起来直观,却常常隐匿了实际的函数调用过程,时常容易让人困惑。所以在google c++编码规范里面,建议直接用普通的成员函数而不是重载运算符。可以看下面的代码段: class... 阅读全文
posted @ 2015-12-22 10:20 sfesly 阅读(156) 评论(0) 推荐(0)
 
 

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)
 
 

2015年12月16日

linux下的文件权限管理
摘要: 权限管理有两个层面第一层区分用户:文件属主(u), 组用户(g), 其它(o)第二层区分权限:读(r),写(w),可执行(x)这两个层次构成文件权限管理的二维结构 u g orwx实际中我们用9个bit位来分别表示这张表里九个位置的值在八进制下就是三位数了所以最常见到的chmod 777 filen... 阅读全文
posted @ 2015-12-16 15:40 sfesly 阅读(211) 评论(0) 推荐(0)
 
 

2015年12月9日

C++ offsetof
摘要: 这是一个宏,用于计算类中某个成员的地址相对于类实例的偏移量在C++11中,要求这个类standard_layout基本用法是这样子的:#include /* printf */#include /* offsetof */struct foo { char a; c... 阅读全文
posted @ 2015-12-09 20:50 sfesly 阅读(1049) 评论(0) 推荐(0)
 
 

2015年12月8日

C++11 std::copy
摘要: 这个函数并不是简单的while(first != last){ *result = *first; result++; first++; }事实上这种写法是最具普适性的,值要求inputIterator是输入迭代器,outputIterator是输出迭代器可以想像我们熟悉... 阅读全文
posted @ 2015-12-08 20:48 sfesly 阅读(957) 评论(0) 推荐(0)
 
 
上一页 1 2 3 4 5 6 7 ··· 13 下一页

公告


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