Effective C++: 55 special ways to improve your programs and designs

Accustoming Yourself to C++

1. View C++ as a federation of languages

2. Prefer const, enums, and inlines to #defines

3. Use const whenever possible

4. Make sure that objects are initialized before the're used


Constructors, Destructors and Assignment Operators

5. Know what functions C++ silently writes and calls

6. Explicitly disallow the use of compiler-generated functions you do not want

7. Declare destructors virtual polymorphic base class

8. Prevent exceptions from leaving destructors

9. Never call virtual functions during construction or destruction

10. Have assignment operators return a reference to *this

11. Handle assignment to self in operator =

12. Copy all parts of an object


Resource Management

13. Use objects to manage resources

14. Think carefully about copying behavior in resource-managing classes

15. Provide access to raw resources in resource-managing classes

16. Use the same form in corresponding uses of new and delete

17. Store newed objects in smart pointers in standalone statements


Designs and Declarations

18. Make interface easy to use correctly and hard to use incorrectly

19. Threat class design as type design

20. Prefer pass-by-reference-to-const to pass-by-value

21. Don't try to return a reference when you must return an object

22. Declare data members private

23. Prefer non-member non-friend functions to member functions

24. Declare non-member functions when type conversions should apply to all parameters

25. Consider support for a non-throwing swap


Implementations

26. Postpone variable definitions as long as possible

27. Minimize casting

28. Avoid returning 'handles' to object internals

29. Strive for exceptions-safe code

30. Understand the ins and outs of inlining

31. Minimize compilation dependencies between files


Inheritance and Object-Oriented Design

32. make sure public inheritance models 'is-a'

33. Avoid hiding inherited names

34. Differentiate between inheritance of interface and inheritances of implementation

35. Consider alternatives to virtual functions

36. Never redefine an inherited non-virtual function

37. Never redefine a function's inherited default parameter value

38. Model 'has-a' or 'is-implement-in-terms-of' through composition

39. Use private inheritance judiciously

40. Use multiple inheritance judiciously


Template and Generic Programming

41. Understand implicit interfaces and compile-time polymorphism

42. Understand the two meaning of typename

43. Know how to access names in templatized base class

44. Factor parameter-independent code out of templates

45. Use member function templates to accept 'all compatible types'

46. Define non-member functions inside templates when type conversions are desired

47. Use truaits classes for information about types 

48. Be aware of template meta-programming


Customizing new and delete

49. Understand the behavior of the new-handler

50. Understand when it makes sense to replace new and delete

51. Adhere to convention when writing new and delete

52. Write placement delete if you write placement new


Miscellany

53. Pay attention to compiler warnings

54. Familiarize yourself with the standard library, including TR1

55. Familiarize yourself with Boost


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Alex Allain(Cprogramming.com)的推荐 If you want to really and truly understand C++, you must read Effective C++. After first reading Effective C++, I had a totally new appreciation for and understanding of C++. And it's not just me: this book gets 5 stars on Amazon (with over 140 reviews!). One of the reviewers even titles his review: "Don't write C++ code without it..." And I agree. I wouldn't hire someone to work for me that doesn't know the information in this book (or have plans to learn it soon). When we hire interns at my company, this is the book we give them to read. So what exactly will you learn? Scott Meyers does a great job of figuring out what little details are important, distilling the vast sea of knowledge about C++ into the 55 specific tips that are most useful for practicing C++ programmers. This isn't just a "what to do" book--it's a "why" book; every tip explains the reason for it, so you'll understand it and remember it better. In fact, even though the book is split across 55 tips, it feels like a holistic description of how to effectively use C++. Some of the specific things you'll learn: what functions are always part of a class and why it matters to you what to watch out for when writing an assignment operator How to avoid common pitfalls when creating class hierarchies how to write code designed for others to use simple techniques that can lead to huge performance improvements advanced C++ techniques, including use of the STL (with lots of examples) And much much more... If you are serious about becoming a C++ expert, buy ONE book on C++, this would be the book. (Yes, even over Bjarne Stroustrup's "The C++ Programming Language"--it's that good.) So buy Effective C++ today and write better programs tomorrow! Alex 49 Dover St. #37, Somerville, MA 02144, USA

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值