December 2001
Intermediate to advanced
304 pages
6h 25m
English
Difficulty: 7
Is it possible to make any C++ class strongly exception-safe, for example, for its copy assignment operator? If so, how? What are the issues and consequences? To illustrate, this Item explains and then solves the Cargill Widget Example.
What are the three common levels of exception safety? Briefly explain each one and why it is important.
What is the canonical form of strongly exception-safe copy assignment?
Consider the following class:
// Example 22-1: The Cargill Widget Example
//
class Widget
{
public:
Widget& operator=( const Widget& ); // ??? // ...
private:
T1 t1_;
T2 t2_;
};
Assume that any T1 or T2 operation might throw. Without changing the structure of the class, ...
Read now
Unlock full access