The information in this article applies to:
SYMPTOMSUnder some circumstances, virtually calling a class member function from within the class's constructor may cause the wrong version of the member function to be called when global optimizations are enabled (/Og or #pragma optimize("g",on) ). Virtually calling a class member function means assigning the value of this to a pointer variable and attempting to call virtual member functions via that pointer. Please see the sample code in the More Information Section below. CAUSEThe vfptr is not being properly initialized. In the sample code below, p in effect becomes an A* instead of a B*. RESOLUTION
One workaround is to disable global optimizations for the class
constructor. Please note the sections of code that compile conditionally
for the constant 'WORKAROUND' in the sample code below. STATUS
Microsoft has confirmed this to be a bug in the Microsoft products
listed at the beginning of this article. This bug has been corrected in
Visual Studio 97 Service Pack 1. Q170365 INFO: Visual Studio 97 Service Packs - What, Where, and Why MORE INFORMATION
Additional query words: /Og Global Optimization
Keywords : kbcode kbtool kbCompiler kbVC420bug kbVC500bug kbVS97sp1fix |
Last Reviewed: July 30, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |