Difficulty: Easy
Correct Answer: Compiler
Explanation:
Introduction / Context:
C++ supports implicitly-declared special member functions to simplify class usage. One is the default constructor, which enables default-initialization of objects when no user-declared constructors exist. This question asks which stage is responsible for creating it.
Given Data / Assumptions:
Concept / Approach:
The compiler analyzes class definitions and, if the rules allow, implicitly declares a default constructor. The preprocessor only handles macros and includes; the linker and loader deal with binary combination and loading; neither invents C++ class members. Hence, the compiler is the correct answer.
Step-by-Step Solution:
1) Write class C {}; with no constructors.2) The compiler implicitly declares C::C().3) You can then write C c; and it compiles.4) If you declare any constructor, the implicit default constructor is no longer provided automatically unless you write C() = default;.
Verification / Alternative check:
Inspect error messages when adding a parameterized constructor but forgetting to add a default one; the compiler will note that C is not default-constructible.
Why Other Options Are Wrong:
Preprocessor/linker/loader: not responsible for generating C++ class members.Run-time library: does not declare constructors.
Common Pitfalls:
Assuming a default constructor will still exist after declaring other constructors; explicitly declare or default it if you need default construction.
Final Answer:
Compiler
Discussion & Comments