Menu

Structures versus classes

Will Pittenger

Classes and structures different in several subtle and not so subtle ways.

Feature Structures Classes
Inheritance Structures can inherit any type other than classes besides Object Classes can inherit any type
By reference versus by value Instances of structures are normally by value; to get a By Reference location, use the ref type modification operator Instances of classes are normally stored in references; to get a By Value location, use the byvalue type modification operator
Interface implementation Structures can't themselves implement interfaces Classes can implement interfaces as needed
Bitfields and unions Structures can use these as needed Classes may not declare bitfields or unions; to do that, drive from a structure that does it for you; Classes can, however, use a typed union

Related

Wiki: Home

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.