Professional C__ - Marc Gregoire [503]
Things to Remember
Overloading stream operators, because they are the most commonly overloaded operators, and are conceptually unique
What a functor is and how to create one
Choosing between a method operator or a global friend function
Some operators can be expressed in terms of others, i.e., operator<= can be written by complementing the result of operator>.
The use of C++11 rvalue references to implement move assignment operators
Types of Questions
Let’s face it — operator overloading questions (other than the simple ones) are cruel. Anybody who is asking such questions knows this and is going to be impressed when you get it right. It’s impossible to predict the exact question that you’ll get, but the number of operators is finite. As long as you’ve seen an example of overloading each operator that makes sense to overload, you’ll do fine!
Besides asking you to implement an overloaded operator, you could be asked high-level questions about overloaded operators. A find-the-bug question could contain an operator that is overloaded to do something that is conceptually wrong for that particular operator. In addition to syntax, keep the use cases and theory of operator overloading in mind.
CHAPTERS 19 AND 20: TEMPLATES
As one of the most arcane parts of C++, templates are a good way for interviewers to separate the C++ novices from the pros. While most interviewers will forgive you for not remembering some of the advanced template syntax, you should go into the interview knowing the basics.
Things to Remember
How to write a basic templatized class
How to use a templatized class
The C++11 alternative function syntax and its use for calculating the type of the return value (type inference)
C++11 template aliases and why they are better than typedefs
The concept of C++11 variadic templates
The ideas behind metaprogramming
Types of Questions
Many interview questions start out with a simple problem and gradually add complexity. Often, interviewers have an endless amount of complexity that they are prepared to add, and they simply want to see how far you get. For example, an interviewer might begin a problem by asking you to create a class that provides sequential access to a fixed number of ints. Next, the class will need to grow to accommodate an arbitrary sized array. Then, it will need arbitrary data types, which is where templates come in. From there, the interviewer could take the problem in a number of directions, asking you to use operator overloading to provide array-like syntax, or continuing down the template path by asking you to provide a default type.
Templates are more likely to be employed in the solution of another coding problem than to be asked about explicitly. You should brush up on the basics in case the subject comes up. However, most interviewers understand that the template syntax is difficult, and asking someone to write complex template code in an interview is rather cruel.
The interviewer might ask you high-level questions related to metaprogramming to find out whether you have heard about it or not. While explaining, you could give a small example such as compile-time loop unrolling. Don’t worry if the syntax for your example is not entirely correct. As long as you explain what it is supposed to do, you should be fine.
CHAPTER 21: EFFECTIVE MEMORY MANAGEMENT
You can be sure that an interviewer will ask you some questions related to memory management, including your knowledge of smart pointers. Besides smart pointers, you will also get more low-level questions. The goal is to determine whether the object-oriented aspects of C++ have distanced you too much from the underlying implementation details. Memory management questions will give you a chance to prove that you know what’s really going on.
Things to Remember
Drawing the stack and the heap can help you understand what’s going