Article ID: 151500
Article Last Modified on 12/10/2003
170365 INFO: Visual Studio 97 Service Packs - What, Where, and Why
/* Compile Options: /Og
// uncomment the following to illustrate the workaround which
// disables global optimizations for the constructor
//#define WORKAROUND
class A
{
public:
virtual void f() = 0;
virtual void g();
};
void A::g()
{
}
class B : public A
{
public:
B();
virtual void f();
virtual void g();
};
void B::f()
{
}
void B::g()
{
}
#ifdef WORKAROUND
#pragma optimize("g",off)
#endif // WORKAROUND
B::B()
{
B* p = this;
// If p->g() is changed to this->g(), or simply g(), the
// correct member function (B::g) is called.
p->g(); // Actually calls A::g()
// if p->f() is changed to this->f(), or simply f(), the
// correct member function (B::f) is called.
p->f(); // Actually calls A::f(), which causes a runtime error
}
#ifdef WORKAROUND
#pragma optimize("g",on)
#endif //WORKAROUND
int main()
{
B b;
return 0;
}
Additional query words: /Og Global Optimization
Keywords: kbbug kbfix kbvs97sp1fix kbcode kbcompiler KB151500