项目中的某些类别,比如说商品,是推荐使用struct来构建还是class呢? #3
Answered
by
liusy58
tang-mouren
asked this question in
Q&A
-
Beta Was this translation helpful? Give feedback.
Answered by
liusy58
Feb 19, 2022
Replies: 2 comments
-
|
两者并没有很大的区别,C++为了向下兼容仍然保留了struct,当然还是更推荐class. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
RicoloveFeng
-
|
在 C++ 里面 struct 就是一种特殊的 class。如果你想像 C 那样弄一个 struct,实际上让 class 的成员变量全 public 就能有同样的效果。重点在于怎么设计各个类之间的分工,而不至于弄出一个「用 class 包起来的 main 函数」这样的东西。 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
两者并没有很大的区别,C++为了向下兼容仍然保留了struct,当然还是更推荐class.