Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.lang.c++.moderated    |    Moderated discussion of C++ superhackery    |    33,346 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 32,564 of 33,346    |
|    =?windows-1252?Q?Daniel_Kr=FCgler?= to All    |
|    Re: Cannot convert =?windows-1252?Q?=91i    |
|    25 Sep 12 13:46:53    |
      From: daniel.kruegler@googlemail.com              Am 25.09.2012 22:14, schrieb kiran:       > Here is a code snippet:       > =============       > int **ptr;       > int intArr[3][5];       > ptr = intArr;       > =============       >       > This gives the error on g++ compiler:       > error: cannot convert ‘int [3][5]’ to ‘int**’ in assignment       >       > I have tried other variants as well, like       > int const **ptr = intArr;       > and       > ptr = &intArr[0];       >       > I still got the same error. Can anyone explain the reason here.              The reason for this is, because array-to-pointer conversion does not       have an arbitrary depth. The relevant wording in 4.2 [conv.array] p1 is:              "An lvalue or rvalue of type “array of N T” or “array of unknown bound       of T” can be converted to a prvalue of type “pointer to T”. The result       is a pointer to the first element of the array."              Applied to your example we have intArr, which has type "array of 3 array       of 5 int". The quoted wording says that this type can undergo an       array-to-pointer conversion to type "pointer to array of 5 int", which       can be written as the type int (*)[5]. Note that at this point we have       no longer an array anymore, therefore no further decay to int** is possible.              HTH & Greetings from Bremen,              Daniel Krügler                     --        [ See http://www.gotw.ca/resources/clcm.htm for info about ]        [ comp.lang.c++.moderated. First time posters: Do this! ]              --- SoupGate-Win32 v1.05        * Origin: you cannot sedate... all the things you hate (1:229/2)    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca