const decltype(p1) p2 means int* const p2 .
This means that you cannot change p2 , but you can change what it points to.
const T always applies const to the so-called "upper level" T When T is a composite type (that is, a type created from a basic set of types), you will have to jump over the hoops if you want to apply const to the lower levels.
When T is int * , adding a top level const will give int * const . * marks the level; to get the information below * , you need to manually remove * , apply const , and then return * .
Possible Solution:
const std::remove_pointer<decltype(p1)>::type *p2 = new int(100);
source share