文件read()const正确性 [英] file read() const correctness

查看:171
本文介绍了文件read()const正确性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我正在写一个类来包装窗口的文件HANDLE,以提供从文件轻松读/写的功能。该类有一个函数 read(buffer& out)从文件读取数据。



read()需要 const 还是不?



一方面,它应该是 const ,因为它不会更改文件。
另一方面,它不应该是 const ,因为它改变了HANDLE(HANDLE到显示读取位置的文件)。



你觉得怎么样?

解决方案

修改文件句柄位置。


Assume I am writing a class to wrap windows' file HANDLE to give functionality to read/write from files easily. The class has a functions called read(buffer& out) that reads data from the file.

The question is, does read() need to be const or not?

On one hand, it should be const because it doesn't change the file. On the other hand, it shouldn't be const because it changes the HANDLE (the HANDLE to the file which shows where to read).

What do you think?

解决方案

Not const. Modifies the file handle position.

这篇关于文件read()const正确性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆