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.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *