Is it sane to let a read method on a file object to be const? For example
size_t read(void* buffer,size_t length) const;
The read method does not change the contents of the file, but updates the file pointer which is invisible behind a handle.
|
Is it sane to let a read method on a file object to be const? For example
The read method does not change the contents of the file, but updates the file pointer which is invisible behind a handle. |
|||||
|
|
Although the Marking a method const has two meanings: One to the programmer, and a different one to the compiler.
To that end, you mark a method as const if it meets the programmers's definition of having no visible side effects. The compiler's definition of const is merely a tool that the compiler can use to check your claim that the method is idempotent. The mutable keyword, which you use to tell the compiler that this piece of an object's state can be changed and have no visible side effects, is both a tool used to adapt the compiler's understanding of |
|||||||
|