Answer the following C++ conceptual questions:
-
C++ standard containers implementation
For common C++ standard library containers such as
std::vector
,
std::list
,
std::map
, and
std::unordered_map
:
-
What are their typical underlying data structures and memory layouts?
-
What are their key performance characteristics (time complexity of insert, erase, random access, iteration)?
-
In what scenarios would you prefer one container over another?
-
Segmentation fault causes
In C or C++, what is a segmentation fault, and in what typical situations can it occur?
Give several concrete examples involving pointers, arrays, and memory management.
-
Virtual constructors in C++
Can a constructor in C++ be declared as
virtual
? Why or why not?
Explain the language and object model reasons behind this, and mention common patterns used when people think they "need" a virtual constructor.
-
How virtual functions find the correct implementation
How does C++ implement virtual function dispatch under the hood?
Explain how the program decides at runtime which overridden function to call when you invoke a virtual method through a base-class pointer or reference.
Include in your explanation:
-
The roles of the vtable and vptr (or equivalent mechanisms).
-
What happens with single inheritance vs. multiple inheritance at a high level.
-
Any special considerations during construction and destruction.