Redian新闻
>
Can a struct be derived? in C#, in C++
avatar
k*i
2
I don't think so

【在 f******l 的大作中提到】
: can you say:
: strcut A {
: ...
: }
: struct B : A {
: ...
: }

avatar
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
avatar
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#.

avatar
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

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。