Conversion with a pointer to a pointer to a constant

I am reading a book called C ++ Gotchas , which explains the conversions between constant pointers, and I am having some problems understanding the following rules:

Two types of pointers T1 and T2 are similar if there is a type T and an integer n> 0 such that:

T1 is cv 1, 0 pointer to pointer cv 1,1., Cv 1, n-1 pointer to cv 1, n T

and

T2 - cv 2,0 pointer to pointer cv 2,1., 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 in the right direction where I can get an explanation, or is anyone familiar with what cv 1.0 and cv 1.1 mean in each of the above sequence? The book does not help me to understand this. But I'm sure this is related to the C ++ language.

+4
source share
1 answer

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

For each combination i with 1 <= i <= 2 and j with 0 <= j <= n placeholder cv i,j denotes one of the three qualifiers const,volatile, const volatlie or nothing.

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

For example, T1 = const int* and T2 = int* are similar because they populate two statements from the excerpt if you select:

  • 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 a pointer to const int

int* is a pointer to int

+4
source

Source: https://habr.com/ru/post/1387318/


All Articles