Difficulty: Easy
Correct Answer: type-specific
Explanation:
Introduction / Context:
Modern C++ emphasizes reusable, generic containers (such as std::vector, std::list, std::map). Properly designed container classes separate algorithms and storage from specific element types, enabling code reuse across many domains with minimal duplication. This question probes the idea that well-designed containers are not tied to a single data type.
Given Data / Assumptions:
Concept / Approach:
When containers are generic, they operate on parameterized types. This means the tools (APIs, algorithms) work with structures that are not type-specific. The container code does not care whether it holds int, std::string, or a user-defined class, as long as required operations are available. This decoupling yields strong reuse and composability.
Step-by-Step Solution:
Design containers with type parameters (e.g., template
Verification / Alternative check:
std::vector
Why Other Options Are Wrong:
Common Pitfalls:
Designing containers with assumptions about specific types (e.g., relying on particular fields) harms reuse. Prefer type constraints expressed via concepts or documented requirements.
Final Answer:
type-specific.
Discussion & Comments