开发者

Should a file header be a class or a struct?

开发者 https://www.devze.com 2023-03-22 16:17 出处:网络
I\'m parsing a file format with a header. (Note: I don\'t write any files, I only read and parse) Because it won\'t be changed, its header can be passed by value.

I'm parsing a file format with a header. (Note: I don't write any files, I only read and parse)

Because it won't be changed, its header can be passed by value. So I would guess a struct would be the best choice but I'm not sure because I almost never use them.

Is there any reason why I should (not) make it a class or a struct?

Edit: It's hard to provide an example at the moment. You can compare it to any basic file header. It includes the si开发者_Python百科gnature ('magic number'), the version and the 'sub-type'.


The "won't be changed" part is an indicator for immutable, not for value-type.

You probably want a class, but it's impossible to be sure without an example.


If you are going to use Serialization then I suggest class.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号