C++ Fundamentals Phone Screen
Role: Optimus - C++ Generalist
Frequency: Reported
Reported phone screens asked at least five short questions selected from topics such as:
- fundamental types and casts;
- RAII and deterministic cleanup;
- runtime polymorphism and virtual tables;
- standard-library containers and algorithms;
- ownership with smart pointers;
- the different meanings of
static; and - templates, destructors, and language restrictions around
main.
One documented rubric treated fewer than four correct answers out of five as a significant negative signal. The exact question wording and code snippets were not retained.
Variant (interviewer question bank, verbatim)
A shared interviewer question bank posted in an Autopilot C++ channel preserved the full wording of the screening questions and the expert-level follow-ups. It matches the topic list above.
Part 1: The "Simple" Screening Questions
These questions are designed to verify basic competency.
1. Types
- Integers: What is a portable type to represent a 16-bit unsigned integer?
- Casts:
- Explain static_cast, dynamic_cast, and reinterpret_cast.
- What is the difference between C-style casting and C++'s static_cast?
- Can you remove constness with static_cast?
- Pointers & References: What are the differences between pointers and references?
- Struct vs Class: What is the difference between a struct and a class?
- Sizes: What common type is used to represent sizes?
- Static Variables: What is the lifetime of a static variable?
- Function Calls:
- What are the different ways to pass variables & objects to a function?
- Scenario: Passing a std::vector of std::strings to a function:
- How do you pass it so the function won't modify the collection?
- How do you pass it so the function could modify the collection?
2. Memory Management
- Allocation: When/how does C++ allocate on the stack vs. the heap?
- Dynamic Memory: How do you handle dynamic allocation and freeing in C++?
- RAII: What is RAII (Resource Acquisition Is Initialization)? Why should you use it?
3. Object-Oriented Programming
- Polymorphism: What is polymorphism? What are the types in C++ (static & dynamic)?
- Implementation: How is dynamic polymorphism implemented in C++?
- Multiple Inheritance: Why is it generally considered a bad thing to do?
- How does C++ try to fix a specific problem that can occur with multiple inheritance?
- Interfaces: Interface vs. Abstract Base Class? How do you implement both in C++?
- Virtual Destructors: Why should a virtual base class have a virtual destructor?
- Constructors: How to call a parent class' constructor from a daughter's constructor?
- Static Methods: What is a static method? How is it implemented and called?
- Non-copyable: How do you make an object non-copyable?
- Const Correctness: What is the particularity of a getter method signature regarding const?
4. STL (Standard Template Library)
- Maps: Declare a map of (string to (vector of int)) and iterate to print every integer.
- Lists: Delete all elements of a std::list of integers that are negative.
- Map Types: Differences between map and unordered_map?
- Sets: What are the characteristics of a std::set?
5. C++11 & Modern C++
- Variables: Modern way of #define'ing variables?
- Null: Modern way of NULL? Is it better and why?
- Smart Pointers:
- shared_ptr vs unique_ptr? How to create them? (Bonus: weak_ptr?)
- How to transfer/pass a unique_ptr to an object constructor which should store it internally?
- Function Pointers: Modern way of dealing with function pointers?
- Loops: Iterating through a map of strings to vectors of lists of strings: shorter form for the outer loop?
6. Overall Software Engineering
- Libraries: Static VS Shared libraries? (Note: It is surprising how many people can't even explain that).
7. Linkage
- Static Keyword: What are the uses of the static keyword in C++?
- (1) Static class member.
- (2) Static variable at file scope/namespace scope (internal linkage).
- (3) Static function-local variable (global variable).
- Note: A strong candidate will know that in C++11, initialization of static function-local variables is thread-safe (Meyers' singleton technique).
Part 2: Brain Teasers / Expert Questions
Anyone claiming to be an expert should be able to provide a thoughtful answer to these.
1. Why does the standard say that "a virtual function shall not be a template"? (Alternatively: "Can a virtual function be a template? If not, why not?")
Answer: Normally, when a class definition is finished, there is a fixed set of virtual function declarations and no new ones can be added later. Each virtual function must correspond to a fixed index in the vtable. The compiler, as soon as it has the complete class definition, knows what the index will be for each virtual function. This allows it to emit the right object code for a virtual call to that function.
If new virtual functions can be added to a class as a byproduct of template instantiation (which may occur in other compilation units), then the compiler would not be able to figure out the correct indices for all different virtual functions. It would have to look at all other compilation units to find all possible virtual calls against this class and assign vtable indices to each one, which it cannot do — the compiler can only see one compilation unit at a time. (Those other compilation units may not even be available, e.g., in a shared library).
2. Why is it illegal for main to call itself recursively?
Answer: The calling of main is tied to static initialization. Static initialization occurs before main is called; it is not supposed to happen twice in the program and will generally cause undefined behavior. Even if there are no nontrivial global variables, it is still illegal to call main twice.
3. Why is it bad to throw an exception from the destructor? (Alternatively: "Is it okay to throw an exception from the constructor? From the destructor?")
Answer: It is normally okay to throw an exception from the constructor (ctor). Bjarne Stroustrup says it is the "best" way to signal an error in the ctor because otherwise, you cannot abort the creation of the object. The alternative is creating the object in a "null" or "failed" state.
Throwing from a destructor (dtor) is bad for many reasons:
- Standard Library Incompatibility: The standard library does not support your type if you do this; you get undefined behavior if you put it in std::vector, for instance.
- Implicit noexcept: In C++11 and forward, destructors are usually implicitly declared noexcept. This means std::terminate will be called if you throw. You can explicitly declare them noexcept(false), but that's usually a bad idea.
- The Fundamental Reason (Double Exception): Destructors play a fundamental role in C++ error handling (RAII). When an exception is thrown, the program exits the current scope and destroys local variables (stack unwinding). If one of those destructors throws an exception while the first exception is already being handled ("in-flight"), you now have two active exceptions.
- This is fundamentally impossible to handle. The program cannot decide which exception to ignore.
- The standard dictates that if two exceptions are in-flight at the same time, std::terminate is called immediately.
- Since the primary role of destructors is to support RAII, the only thing that should generally happen in a destructor is the release of resources. Releasing a resource should not fail.
Summary: It is okay for an exception to be thrown within a destructor, as long as it is caught and handled inside the destructor — it must not propagate out.
Source: community report, April 2026