FIX: C++ Compiler Treats &array[][] as 2-D Array of References

Last reviewed: September 18, 1997
Article ID: Q115708
7.00 | 1.00 1.50 | 1.00
MS-DOS | WINDOWS   | WINDOWS NT
kbtool kbfixlist kbbuglist

The information in this article applies to:

  • The Microsoft C/C++ Compiler (CL.EXE), included with:

        - Microsoft C/C++ for MS-DOS, version 7.0
        - Microsoft Visual C++ for Windows, versions 1.0 and 1.5
        - Microsoft Visual C++ 32-bit Edition, version 1.0
    

SYMPTOMS

Attempting to call a class constructor using a reference to a two dimensional array of objects will cause the compiler to incorrectly treat the array as a two dimensional array of references. In the sample below, the following errors will be incorrectly generated:

   test.cpp(6) : error C2234: arrays of references are illegal
   test.cpp(6) : error C2511: '__ctor' : overloaded member function
                 not found in 'X'

CAUSE

The compiler is interpreting

   int (&iref)[10][10];

as if it was written:

   int & iref[10][10];

It is not legal in C++ to use a pointer to a reference, so an array of references is also not legal.

STATUS

Microsoft has confirmed this to be a bug in the C/C++ compiler for MS-DOS, versions 7.0, 8.0, and 8.0c and the 32-bit C/C++ compiler, version 8.0. This problem was corrected in compiler version 9.0, included with Visual C++ version 2.0.

MORE INFORMATION

The following code can be used to demonstrate this problem.

Sample Code

/* Compile options needed: /c
*/

class X {
    int m_arr[10][10];
public:
    X() {}
    X( int (&iref)[10][10] ) {}
};

void main()
{ }


Additional reference words: 7.00 8.00 8.00c 1.00 1.50
KBCategory: kbtool kbfixlist kbbuglist
KBSubcategory: CPPIss
Keywords : CPPIss kbbuglist kbfixlist kbtool
Version : 7.00 | 1.00 1.50 | 1.00
Platform : MS-DOS NT WINDOWS
Solution Type : kbfix


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: September 18, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.