Error decltype C2440 cannot convert from 'int *' to 'int * &'

The following is a contrived example of actual code:

int** Ptr = 0;
decltype(Ptr[0]) Test = (int*)0;

I get an error message:

error C2440: 'initializing': cannot convert from 'int *' to 'int * &'

I am not sure why I get this, because from my understanding decltype(correct me if I am wrong), he simply accepts any expression that you give him and allow it to its actual type. In this case Ptr[0]there is int*, so I expect:int* Test = (int*)0;

What am I missing? Why am I getting this error?

+3
source share
1 answer

++ 7.1.6.2 [dcl.type.simple] , . decltype :

e , decltype (e), :

, , ( ):

  • e - id- unparenthesized (5.2.5), decltype (e) , e. e , ;

lvalue:

  • , e lvalue, decltype (e) T &, T - e;

.

M.M std:: remove_reference, :

std::remove_reference<decltype(Ptr[0])>::type Test = (int*)0;

T.C. std:: decay :

std::decay<decltype(Ptr[0])>::type Test = (int*)0;
+5

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


All Articles