See C ++ Primer of 58, can not ignore the underlying const said when speaking here of copies of the reasons a little far-fetched, given his understanding here

but external const int = 42; 

const int * p2  = &ci;

extern const  int *const p3= p2;  

int * p = p3; // wrong, p no underlying const.

It is explained in the book: p3 is the bottom layer is the top const const, p3 copies could care const top layer, but the point p3 is a constant, and therefore can not be used to initialize P3 p, and p is the amount of points only. I understand what he meant because a pointer to point to a very constant amount.

But they think about it, the underlying const can also point to a great amount, it is not when p3 very outset, when the amount of initialization, this time p3 and p point to a const, int * p = p3; is not it correct of it? If you press on the interpretation of the book, giving the misconception when they both point to a very constant amount or no problem, this is a misunderstanding, misunderstanding because he was not clear.

  This is what I understand: a constant pointer pointing to either point to the constant can also point to very volume, while ordinary pointers can point to very amount.

1, while having no underlayer const is assumed to be copied:

When a pointer to the underlying const const pointer assignment without an underlying, because the former can be constant or very point amount, which amount is only point, the former does not matter. I feel nothing wrong.

Now turn:

When there is no underlying const pointer to const pointer has the underlying assignment, because the former can only point to a very amount, which may point to a constant or very amount, the question is: when the latter point is very volume, are just the very amount, as referent value can not be changed, which it is both its own grammar provisions of the problem, not related; but when the latter is a constant point of time, because the former can only point to a very amount that the assigned address of the object to you, I can not point to the lack of a constant, which is a contradiction. So, at this point in the case because it can not meet both the rules of grammar. So simply must have specified the assignment of both the underlying const. This will avoid this situation. Whether or not such a provision this reason, it can be understood that provision.

2, or so we understand: int * pointer to an object type must match, and the pointer is pointing to the constant const int *, type mismatch, it can not be copied, can not be initialized. Constant pointer to be understood that the same value as pointer

3, or may be so understanding: great amount can be converted to a constant, constant amount can not be converted to a very: int * can be converted to const int *, not vice versa.

 

  I do not know the above three kinds of understanding is not correct, please understand the real reason for the god of eliminating A puzzled ah.

 

Guess you like

Origin www.cnblogs.com/qzhj-pipeofnaturalrule/p/12244379.html