Ray's playground

 
上一页 1 ··· 8 9 10 11 12 13 14 15 16 ··· 56 下一页

2011年3月28日

Item 25: Consider support for a non-throwing swap(Effective C++)

摘要: Provide a swap member function when std::swap would be inefficient for your type. Make sure your swap doesn't throw exceptions. If you offer a member swap, also offer a non-member swap that calls the member. For classes (not templates), specialize std::swap, too. When calling swap, employ a usin 阅读全文

posted @ 2011-03-28 20:41 Ray Z 阅读(204) 评论(0) 推荐(0) 编辑

Item 24: Declare non-member functions when type conversions should apply to all parameters(Effective C++)

摘要: If you need type conversions on all parameters to a function (including the one pointed to by the this pointer), the function must be a non-member. 阅读全文

posted @ 2011-03-28 17:54 Ray Z 阅读(149) 评论(0) 推荐(0) 编辑

Project Euler Problem 23

摘要: A perfect number is a number for which the sum of its proper divisors is exactly equal to the number. For example, the sum of the proper divisors of 28 would be 1 + 2 + 4 + 7 + 14 = 28, which means that 28 is a perfect number.A numbernis called deficient if the sum of its proper divisors is less tha 阅读全文

posted @ 2011-03-28 15:26 Ray Z 阅读(254) 评论(0) 推荐(0) 编辑

Item 23: Prefer non-member non-friend functions to member functions(Effective C++)

摘要: Prefer non-member non-friend functions to member functions. Doing so increases encapsulation, packaging flexibility, and functional extensibility. 阅读全文

posted @ 2011-03-28 12:02 Ray Z 阅读(155) 评论(0) 推荐(0) 编辑

Manipulating Strings(Chapter 6 of Objective-C Phrasebook)

摘要: Foundation provides a class for assigningarbitrary attributes to strings. TheNSAttributedString class lets you attachdictionaries to ranges in attributed strings.These dictionaries can contain any arbitraryinformation that you want, including semanticmarkup. It’s important to remember that sending . 阅读全文

posted @ 2011-03-28 11:48 Ray Z 阅读(173) 评论(1) 推荐(0) 编辑

2011年3月27日

Item 22: Declare data members private(Effective C++)

摘要: Declare data members private. It gives clients syntactically uniform access to data, affords fine-grained access control, allows invariants to be enforced, and offers class authors implementation flexibility. protected is no more encapsulated than public. 阅读全文

posted @ 2011-03-27 20:56 Ray Z 阅读(181) 评论(0) 推荐(0) 编辑

Item 21: Don't try to return a reference when you must return an object(Effective C++)

摘要: Never return a pointer or reference to a local stack object, a reference to a heap-allocated object, or a pointer or reference to a local static object if there is a chance that more than one such object will be needed. 阅读全文

posted @ 2011-03-27 10:45 Ray Z 阅读(218) 评论(0) 推荐(0) 编辑

2011年3月24日

bitset

摘要: 1#include<iostream>2#include<bitset>3usingnamespacestd;45intmain()6{7bitset<16>a(0xff01);8cout<<"a:"<<a<<endl;910bitset<32>b("100010");11cout<<"b:"<<b<<endl;12cout<<"countofb:"<<b.count()& 阅读全文

posted @ 2011-03-24 22:03 Ray Z 阅读(151) 评论(0) 推荐(0) 编辑

Item 20: Prefer pass-by-reference-to-const to pass-by-value(Effective C++)

摘要: Prefer pass-by-reference-to-const over pass-by-value. It's typically more efficient and it avoids the slicing problem. The rule doesn't apply to built-in types and STL iterator and function object types. For them, pass-by-value is usually appropriate. 阅读全文

posted @ 2011-03-24 21:35 Ray Z 阅读(167) 评论(0) 推荐(0) 编辑

Item 19: Treat class design as type design(Effective C++)

摘要: Class design is type design. Before defining a new type, be sure to consider all the issues discussed in this Item. 阅读全文

posted @ 2011-03-24 20:54 Ray Z 阅读(167) 评论(0) 推荐(0) 编辑

上一页 1 ··· 8 9 10 11 12 13 14 15 16 ··· 56 下一页

导航