While spelunking through the code of a new project you recently joined, you find the following factory function declaration: JG Question 1. What’s wrong with this return type? Guru Questions 2. What is the recommended return type? Explain your answer, including any tradeoffs. 3. You’d like to actually change the return type to [...]
Archive for the ‘GotW’ Category
GotW #104: Smart Pointers, Part 2 (Difficulty: 5/10)
Posted in C++, GotW on 2012-04-21 | 25 Comments »
GotW #103: Solution
Posted in C++, GotW on 2012-04-21 | 3 Comments »
The solution to GotW #103 is now live.
GotW #103: Smart Pointers, Part 1 (Difficulty: 3/10)
Posted in C++, GotW on 2012-01-20 | 11 Comments »
JG Question 1. When should you use shared_ptr vs. unique_ptr? List as many considerations as you can. Guru Questions 2. Why should you always use make_shared to allocate objects whose lifetimes will be managed by shared_ptr? Explain. 3. What’s the deal with auto_ptr?
The solution to GotW #102 is now live.
GotW #102: Exception-Safe Function Calls (Difficulty: 7/10)
Posted in C++, GotW on 2011-12-02 | 30 Comments »
JG Question 1. In each of the following statements, what can you say about the order of evaluation of the functions f, g, and h and the expressions expr1 and expr2? Assume that expr1 and expr2 do not contain more function calls. Guru Questions 2. In your travels through the dusty corners of your company’s [...]
GotW #101: Solution
Posted in C++, GotW on 2011-12-02 | 14 Comments »
The solution to GotW #101 is now live.
GotW #101: Compilation Firewalls, Part 2 (Difficulty: 8/10)
Posted in C++, GotW on 2011-11-16 | 10 Comments »
GotW #100 demonstrated the best way to express the Pimpl idiom using only standard C++11 features: Guru Question Is it possible to make the widget code easier to write by wrapping the Pimpl pattern in some sort of library helper? If so, how? Try to make the widget code as convenient and concise as possible [...]
GotW #100: Solution
Posted in C++, GotW on 2011-11-16 | 8 Comments »
The solution to GotW #100 is now live.
GotW #100: Compilation Firewalls
Posted in C++, GotW on 2011-11-04 | 23 Comments »
JG Questions 1. What is the Pimpl Idiom, and why is it useful? Guru Questions 2. What is the best way to express the basic Pimpl Idiom in C++11? 3. What parts of the class should go into the impl object? Some potential options include: put all private data (but not functions) into impl; put [...]