Skip to content

Instantly share code, notes, and snippets.

@julienetie
Last active September 21, 2024 19:01
Show Gist options
  • Select an option

  • Save julienetie/5027d67b5e308552ce6f724eb2317f6b to your computer and use it in GitHub Desktop.

Select an option

Save julienetie/5027d67b5e308552ce6f724eb2317f6b to your computer and use it in GitHub Desktop.
Structs vs Classes
Language Inheritance Encapsulation Polymorphism Constructors Static Members Multiple Inheritance Method Overriding Method Overloading
C struct ❌ ✅ ❌ ❌ ✅ ❌ ❌ ❌
C class NA NA NA NA NA NA NA NA
C++ struct ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅
C++ class ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅
C# struct ❌ ✅ ❌ ✅ ✅ ❌ ❌ ✅
C# class ✅ ✅ ✅ ✅ ✅ ❌ ✅ ✅
Swift struct ❌ ✅ ❌ ✅ ✅ ❌ ❌ ✅
Swift class ✅ ✅ ✅ ✅ ✅ ❌ ✅ ✅
Zig struct ❌ ✅ ❌ ❌ ✅ ❌ ❌ ❌
Zig class NA NA NA NA NA NA NA NA
Rust struct ❌ ✅ ❌ ✅ ✅ ❌ ❌ ❌
Rust class NA NA NA NA NA NA NA NA
Go struct ❌ ✅ ❌ ❌ ❌ ❌ ❌ ❌
Go class NA NA NA NA NA NA NA NA
Odin struct ❌ ✅ ❌ ❌ ✅ ❌ ❌ ✅
Odin class NA NA NA NA NA NA NA NA
D struct ❌ ✅ ❌ ✅ ✅ ❌ ❌ ✅
D class ✅ ✅ ✅ ✅ ✅ ❌ ✅ ✅
V struct ❌ ✅ ❌ ❌ ✅ ❌ ❌ ❌
V class ✅ ✅ ✅ ✅ ✅ ❌ ✅ ✅
Nim struct ❌ ✅ ❌ ✅ ✅ ❌ ❌ ✅
Nim class NA NA NA NA NA NA NA NA
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment