| FIX: Non-const Conversion Operators Allowed on const ObjectLast reviewed: September 18, 1997Article ID: Q132165 | 
| 7.00   | 1.00 1.50 1.51 1.52 | 1.00 2.00 2.10 2.20 MS-DOS | WINDOWS | WINDOWS NTkbtool kbbuglist kbfixlist The information in this article applies to: 
 
 SYMPTOMSVisual C++ illegally allows use of non-const member functions with const objects. Because of this, const data could be modified. Visual C++ correctly generates errors in most situations where non-const member functions are used on const objects, but fails to generate errors in the case of non-const conversion operators. 
 STATUSMicrosoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This bug was corrected in Microsoft Visual C++, 32-bit Edition, version 4.0. 
 MORE INFORMATIONThe sample code should generate this error message: 
     error C2664: 'x_t::x_t(const struct x_t&)' : cannot convert
         parameter 1 from 'struct x_t*const ' to 'const struct x_t&'
Sample Code to Reproduce Problem
 /* Compile options needed: none */struct x_t {   int i;
  operator int() {return i;}
};
 void func(const x_t& x){ int j = (int)x; //C2664 should be generated on this line } | 
| Additional reference words: 1.00 2.00 2.10 2.20 7.00 8.00 8.00c 9.00 9.10 
 © 1998 Microsoft Corporation. All rights reserved. Terms of Use. |