You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It is often useful to be able to share common functionality across multiple classes without defining an "as-is" relationship, as multiple inheritance is not supported in Corto.
Mixins differ from interfaces in that common functionality is "copied into" the class, whereas an interface guarantees that the class implements a specific method. In addition, mixins will be able to contain members, whereas interfaces can only contain methods.
Because memory layout of members of a mixin cannot be guaranteed across the classes in which a mixin is used, methods implemented by the mixin require an additional level of indirection when accessing mixin members. Therefore the language binding for mixin will be different from that of regular classes.
For example, the following mixin & class definition:
structcanEat {
corto_int32*hunger; // indirection, actual member is resolved at runtime
};
typedefstructmammal_s*mammal;
structmammal_s {
corto_int32hunger; // inserted from mixin
};
It is often useful to be able to share common functionality across multiple classes without defining an "as-is" relationship, as multiple inheritance is not supported in Corto.
For information on mixins and usage in other languages, see: https://en.wikipedia.org/wiki/Mixin
Mixins differ from interfaces in that common functionality is "copied into" the class, whereas an interface guarantees that the class implements a specific method. In addition, mixins will be able to contain members, whereas interfaces can only contain methods.
Because memory layout of members of a mixin cannot be guaranteed across the classes in which a mixin is used, methods implemented by the mixin require an additional level of indirection when accessing mixin members. Therefore the language binding for mixin will be different from that of regular classes.
For example, the following mixin & class definition:
could result in the following C/C++ definition:
and the implementation could look like:
The mixin can then be instantiated and used as follows:
The text was updated successfully, but these errors were encountered: