Which of the following scenarios is most suitable for using a struct instead of a class?
- When needing multiple inheritance.
- When encapsulation and private members are vital.
- When only simple data storage without methods is required.
- When polymorphism is a primary concern.
In C++, both structs and classes can have member functions, inherit from others, and serve many of the same roles. The primary difference is the default access level (structs default to public; classes default to private). However, structs are conventionally used for simple data storage without associated behavior or methods.
Loading...
Related Quiz
- The result of dividing two integers in C++ is always a(n) _______.
- What is the primary purpose of a function in C++ programming?
- In what scenario might a weak_ptr be particularly useful to prevent?
- What does the new operator do in C++?
- Declaring a function as a friend within a class _______ make that function a member of the class.