I have a variable defined in one of my files, It may be manipulated by the code in the file itself, but it is always a constant value to any external file.
How do i declare the variable as constant without raising errors on assigning this variable a value inside the file it is defined in while allowing compiler to optimize it’s read as if it is a constant in those external units ?
A rvalue can’t be modified. Use an accessor function to access it guarantees you only offer an rvalue, e.g.
This makes:
Alternatively you can expose your value via a
constpointer to aconst int: