Why does a parameter have two const's in its declaration?

3

I'm reading the tutorials on the OpenCV lib site and during reading I saw the declaration of a function with a variable in a format I've never seen. I wanted to know what it means, declare the variable this way. I will post only the prototype of the function because the doubt is simple!

Mat& ScanImageAndReduceRandomAccess(Mat& I, const uchar * const table)

const uchar * const table I know it's a pointer to a unsigned char , but I've never seen two const being used this way! This is my question: What is he trying to say?

    
asked by anonymous 19.01.2017 / 01:44

1 answer

2
const uchar * const table

Pointed objects are composed of two information, a pointer, and the data itself. At first both are changeable.

The first const indicates that the content is constant and can not be changed under normal conditions. But that by itself does not mean it can not point to another completely different object.

The second const indicates that the pointer is also constant and can not be changed.

Then this function gets an argument that is "guaranteed" to be read-only.

Guaranteed is the way to say, there are ways to subvert this, though it should not.

    
19.01.2017 / 02:07