FIX: Call to Member Function with Virtual Base FailsLast reviewed: September 18, 1997Article ID: Q115849 |
1.00
WINDOWS
kbtool kbfixlist kbbuglist
The information in this article applies to:
SYMPTOMSThe use of the /Ob2, /Oe, and /Og optimization switches may cause calls to a member function of a class with a virtual base class to return incorrect values.
RESOLUTIONThere are several workarounds to this problem:
STATUSMicrosoft has confirmed this to be a problem in the Microsoft products listed above. This is not a problem in Visual C++, 32-bit Edition. This problem was corrected in Visual C++ version 1.5.
MORE INFORMATIONThe sample code below can be used to illustrate this problem.
Sample Code
/* Compile options needed: /Ob2 /AC (or /AL or /AH) */ #include <stdio.h> #include <stdlib.h>class A { public: int a; int b; int z; int funcA(int);};
int A::funcA(int i){ return a + b + i;} class B : virtual public A { public: int c; int d; int z; int funcA(int); int funcB(int);};
int B::funcA(int i){ return a + c + i;}
int B::funcB(int i){ return c + d + i;}
void main(void){ A a; a.a = 1; a.b = 2; B b; b.a = 1; b.b = 2; b.c = 3; b.d = 4; if (a.funcA(1) != 4) printf("FAILED on line %d\n", __LINE__); \\ Error occurs on this line if (b.funcA(1) != 5) printf("FAILED on line %d\n", __LINE__); if (b.funcB(1) != 8) printf("FAILED on line %d\n", __LINE__); return 0;}
|
Additional reference words: 1.00 8.00
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |