Question

I'm reading a book called C++ Gotchas which explains the conversions between const pointers and I'm having some trouble understanding the following rules:

Two pointer types T1 and T2 are similar if there exists a type T and integer n > 0 such that:

T1 is cv 1 , 0 pointer to cv 1,1 pointer to . . . cv 1,n−1 pointer to cv 1,n T

and,

T2 is cv 2,0 pointer to cv 2,1 pointer to . . . cv 2,n−1 pointer to cv 2,n T

where each cvi,j is const, volatile, const volatile, or nothing.

Can someone point me to right direction where I can get an explanation or is anyone familiar with what cv 1,0 and cv 1,1 means in each of above sequence ? The book isn't helping me enough to understand it. But I'm sure this has got something to do with C++ language.

Was it helpful?

Solution

cv i,j represents a collection of 2*(n+1) placeholders:

For every combination of i with 1 <= i <= 2 and j with 0 <= j <= n the placeholder cv i,j stands for one of the three specifiers const,volatile, const volatlie or nothing.

The book excerpt in other words means, that if these placeholders and a type T can be found such that the two statements ("T1 is ..") are satisfied, then T1 and T2 are called "similar".

For example T1 = const int* and T2 = int* are similar, because they fullfill the two statements from the excerpt, if one chooses:

  • T = int,n = 1
  • cv1,0= {nothing} and cv1,1 = const
  • cv2,0={nothing} and cv2,1 = {nothing}

To see this, just insert the placeholders:

const int* is pointer to const int

int* is pointer to int

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top