Knowledge Base

FIX: Non-const Member Function Call Via const Object Allowed

Article ID: 167348

Article Last Modified on 12/8/2003


APPLIES TO


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;

   }
				

Keywords: kbbug kbfix kbvc600fix kbcode KB167348