I’m pretty sure one of the reasons is because inheritance implies method 
inheritance, which implies being able to override methods, and that opens a big 
can of worms which will be familiar to any experienced C++ programmers.

Swift struct methods aren’t dynamically dispatched; they’re just function 
calls. But if you could subclass a struct and override methods, then the 
methods would need to be dynamically dispatched … but that implies that structs 
would need to contain vtables (or isa pointers), which makes them a lot more 
heavyweight. Or on the other hand, if struct methods stayed statically 
dispatched, then overriding them would be fraught with peril, for the same 
reason that overriding nonvirtual methods in C++ is generally a very bad idea.

—Jens
_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

Reply via email to