we’re learning about the const keyword in our object oriented c++ class. Our professor says he’s purposely going overboard to help us learn all the possible ways to use the const keyword.
In our assignment he states:
Your constructor parameters should be constant pointers to constant
arrays of constant pointers
could somebody show me what an example of this parameter list would look like as well as explain what each const does? I believe the prototype would look like this:
Square(const char* const []);
- where the first is for the pointer (in this case char*)
- second const is for the array
- but then I don’t know where I would put the third const
any help would be much appreciated.
Let’s see:
An array of pointers:
void * array[10];An array of constant pointers, same as a “constant array”:
void * const array[10].A pointer to the above:
void * const (*pa)[10] = &array;A constant pointer to (2):
void * const (* const pa)[10] = &array;A version of the above where the original array consists of pointers-to-const:
So here’s your constructor signature, for any underlying type and array size:
As to what it’s useful for: Pretty much nothing at all. But it can’t hurt to understand this.