can you say: strcut A { ... } struct B : A { ... }
k*i
2 楼
I don't think so
【在 f******l 的大作中提到】 : can you say: : strcut A { : ... : } : struct B : A { : ... : }
p*n
3 楼
in C++, yes, a struct can inherit from another. actually in C++ world, the only difference btw a struct and a class is that the default access modifiers for methods are different. for class: private for struct:public in C#, it is a different story, structs cannot inherit from other structs however, they can derive from interfaces. it is quite different from class in C#.
【在 k****i 的大作中提到】 : I don't think so
a*t
4 楼
Could somebody provide some sample code on how this is done? if have a list of items, and every item has some common properties (same as the original question). Is there a way so I can access each item's properties with something like item[i].properties ?
only
【在 p***n 的大作中提到】 : in C++, yes, a struct can inherit from another. actually in C++ world, the only : difference btw a struct and a class is that the default access modifiers for : methods are different. for class: private for struct:public : in C#, it is a different story, structs cannot inherit from other structs : however, they can derive from interfaces. it is quite different from class : in C#.
d*p
5 楼
While a struct cannot inherit from another struct, it can extend a interface. Try to define an interface for those common properties;
【在 a*******t 的大作中提到】 : Could somebody provide some sample code on how this is done? : if have a list of items, and every item has some common properties (same as : the original question). Is there a way so I can access each item's properties : with something like item[i].properties ? : : only