FIX: Non-const Member Function Call Via const Object Allowed (167348)



The information in this article applies to:

  • Microsoft Visual C++ 4.0
  • Microsoft Visual C++ 4.1
  • Microsoft Visual C++, 32-bit Enterprise Edition 4.2
  • Microsoft Visual C++, 32-bit Enterprise Edition 5.0
  • Microsoft Visual C++, 32-bit Professional Edition 4.2
  • Microsoft Visual C++, 32-bit Professional Edition 5.0

This article was previously published under Q167348

SYMPTOMS

A compiler error is not generated when a non-const member function is called via a temporary const object.

STATUS

Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article. This problem was corrected in Microsoft Visual C++ version 6.0.

MORE INFORMATION

Sample Code

   /* Compile Options Needed: None */ 
   class myClass
   {
   public:
     const myClass f();
     const myClass g();
   };

   int main( )
   {
     myClass mc;

     mc.f().g();     // The return value of f() is const, but g()
                     // is not a const member function. Therefore,
                     // an error should be generated.
     return 0;

   }
				

Modification Type:MajorLast Reviewed:12/8/2003
Keywords:kbBug kbcode kbfix kbVC600fix KB167348