On Tuesday, 4 June 2013 at 05:41:16 UTC, Rob T wrote:
Manu, I'm wondering that perhaps you should not be using classes at all. You can still create a similar overridable scheme for struct methods, and although it may not be as convenient, it will work. However a big failure point with stucts is the lack of inheritance.

Structs would IMO be far more useful if they had inheritance. Inheritence can be fully removed from the rest of polymorphism, so there's no reason why structs which are not polymorphic cannot inherit.

Actually I'd like to know why structs cannot inherit? I hate it when I end up creating classes when I have no other reason to create a class other than for the ability to inherit.


struct are value type. You can't know the size of a polymorphic type. So you'll have trouble sooner than you imagine.

The best part of that issue is that no problem occur when you copy only partially a struct, but then you corrupt memory when you call a virtual function that rely on thoses data. You can crash at this point, but more likely, you'll just corrupt memory, and the program will fail in some totally unrelated part of the code, depending on compiler switchs, in a non reproducible way.

I assure you this is the kind of problem you don't want to have.

Reply via email to