Correctness correctness - C layer API laying API

What are the appropriate methods for providing const-correctness when writing classes that serve as wrappers for other C style libraries of the API. I started writing a class (Renderer) that translates application rendering calls to corresponding OpenGL calls (and possibly DirectX later). This class does not actually have its own state, which is modified by calls, for example, Renderer :: applyTransform (const Matrix &), but internally calls APIs that change the state of OpenGL. In this case, the labeling of APIs such as const, the right thing, or "changes the observed state" also applies to the OpenGL state that this class wraps, requiring me to make it inappropriate?

This is similar to Const-correctness and hardware recording , but perhaps this is a more specific use case.

+5
source share
3 answers

If you call C functions that accept your member variables with no pointer, these wrapper functions should probably not be const. If they only monitor the state and do not change it, you can make your const methods - even if the C API is not const-correct, you can use const_cast<>either mutablein your member variables as needed.

- , const. , , , const, - , , , - .

+3

const? .

, , ? , , .

+2

- , this - . const, , .

, , const , .

0

All Articles