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.
cv i,j
represents a collection of 2*(n+1) placeholders:For every combination of
i
with1 <= i <= 2
andj
with0 <= j <= n
the placeholdercv i,j
stands for one of the three specifiersconst,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, thenT1
andT2
are called "similar".For example
T1 = const int*
andT2 = int*
are similar, because they fullfill the two statements from the excerpt, if one chooses:T = int
,n = 1
cv1,0= {nothing}
andcv1,1 = const
cv2,0={nothing}
andcv2,1 = {nothing}
To see this, just insert the placeholders:
const int*
is pointer toconst int
int*
is pointer toint