FIX: Modifying Const Temporary Object Doesn't Generate Error (149324)
The information in this article applies to:
- Microsoft Visual C++, 32-bit Editions 4.0
- Microsoft Visual C++, 32-bit Editions 4.1
- Microsoft Visual C++, 32-bit Enterprise Edition 4.2
- Microsoft Visual C++, 32-bit Professional Edition 4.2
- Microsoft Visual C++, 32-bit Enterprise Edition 5.0
- Microsoft Visual C++, 32-bit Professional Edition 5.0
This article was previously published under Q149324 SYMPTOMS
The compiler generates the following error when you invoke a non-const
member function on a const object:
error C2662: 'Set' : cannot convert 'this' pointer from 'const struct
A *' to 'struct A *const '
However, it does not generate this error when you invoke a non-const member function on a const object that is returned by a function.
RESOLUTION
To work around this problem, make the function return a reference to const.
STATUSThis bug was corrected in Microsoft Visual C++, version 6.0.
Modification Type: | Minor | Last Reviewed: | 7/5/2005 |
---|
Keywords: | kbBug kbfix kbVC600fix KB149324 |
---|
|