Prashant Mhatre

Make Money, Programming, Bollywood, Marathi

  • You are here: 
  • Home
  • More Effective C++ Tips

More Effective C++ Tips

Posted on March 7th, 2008


-- Sponsored Links --




Basics.


-- Sponsored Links --


– Distinguish Between Pointers and References.
– Prefer C++­Style Casts.
– Never Treat Arrays Polymorphically.
– Avoid Gratuitous Default Constructors.

Operators.

– Be Wary of User ­Defined Conversion Functions.
– Distinguish Between Prefix and Postfix Forms of Increment and decrement operators.
– Never Overload &&, ||, or,.
– Understand the Different Meanings of New and Delete.

Exceptions.

– Use Destructors to Prevent Resource Leaks.
– Prevent Resource Leaks in Constructors.
– Prevent Exceptions from Leaving Destructors.
– Understand How Throwing an Exception Differs from Passing a Parameter or Calling a Virtual Function.
– Catch Exceptions by Reference.
– Use Exception Specifications Judiciously.
– Understand the Costs of Exception Handling.


Efficiency.

– Remember the 80­20 Rule.
– Consider Using Lazy Evaluation.
– Amortize the Cost of Expected Computations.
– Understand the Origin of Temporary Objects.
– Facilitate the Return Value Optimization.
– Overload to Avoid Implicit Type Conversions.
– Consider Using Op= Instead of Stand ­Alone Op.
– Consider Alternative Libraries.
– Understand the Costs of Virtual Functions, Multiple Inheritance, Virtual Base Classes, and RTTI.


Techniques.

– Virtualizing Constructors and Non­Member Functions.
– Limiting the Number of Objects of a Class.
– Requiring or Prohibiting Heap­Based Objects.
– Smart Pointers.
– Reference Counting.
– Proxy Classes.
– Making Functions Virtual With Respect to More Than One Object.


Miscellany.

– Program in the Future Tense.
– Make Non­Leaf Classes Abstract.
– Understand How to Combine C++ and C in the Same Program.
– Familiarize Yourself With the Language Standards

Filed under Programming |

Comments are closed.