The information in this article applies to:
SYMPTOMSInitializing a "const" reference to an array with a "non-const" array causes incorrect compiler errors to be generated. Two such errors are C2607 and C2561. CAUSEThe C++ compiler does not properly handle initialization of a "const T&", where T is an array. For example, you should be able to initialize a variable of type "const float (&ref)[3][2]" with a variable of type "float [3][2]", but the compiler does not handle this case. Furthermore, interactions between const declarations and typedefs of arrays do not work in all circumstances. RESOLUTIONTo work around the problem, either do not use the const specifier or add explicit casts to the appropriate const types. STATUSMicrosoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. MORE INFORMATIONThe sample code below demonstrates the problem. Compiling it yields at least one of the following error messages: To work around the problem, use each commented line in the program to replace the line immediately above it. Note: Simply removing the const specifier from the getMtx function's return type eliminates the problem. Sample Code
Additional query words: kbVC400bug 8.00 8.00c 9.00
Keywords : kbCompiler kbCPPonly kbVC kbVC100bug kbVC150bug kbVC200bug kbVC400bug kbVC410bug kbVC420bug kbVC500bug kbVC600bug |
Last Reviewed: April 16, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |