What is the difference between struct and class in C++ beyond the default access specifier?

Last updated 21 June 2026

The only language-level difference is the default access: members and base-class inheritance are public in a struct and private in a class. Otherwise they are fully interchangeable: both can have methods, constructors, inheritance, access specifiers, and templates.

  • Default member access:

    • struct: members default to public.

    • class: members default to private.

  • Default inheritance access: struct B : A is public inheritance; class B : A is private inheritance.

  • Everything else is identical: Both support methods, virtual functions, access control, templates, and constructors/destructors.

  • Conventional usage (not enforced): struct is typically used for passive aggregates of public data (POD-like); class for types with invariants and encapsulation.

  • https://utkrusht.ai/blog/cplusplus-interview-questions
  • https://roadmap.sh/questions/cpp
  • https://internshala.com/blog/cpp-coding-interview-questions/
All C++ interview questions