Article ID: 129617
Article Last Modified on 7/5/2005
/* Compile options needed, choose one of the following:
none - To demonstrate the problem.
/DWORKAROUND1 - For workaround 1.
/DWORKAROUND2 - For workaround 2.
/DWORKAROUND3 - For workaround 3.
*/
#include <iostream.h>
class A;
class B
{
B *pBthis;
public:
B() {
pBthis = this;
cout << "-- B ctor called, Created B: " << (long)this << endl;
}
#ifdef WORKAROUND1
B(const A&) {
pBthis = this;
cout << "-- B(A) ctor called, Created B: " << (long)this << endl;
}
#endif
B( const B& b ) {
pBthis = this;
cout << "-- B copy ctor, Created B: " << (long)this << endl;
}
~B() {
cout << "-- B dtor called, Destroyed B: " << (long)this << endl;
if (pBthis != this)
cout << " This B was never constructed!" << endl;
}
};
class A
{
public:
A() { cout << "-- A ctor called" << endl; }
~A() { cout << "-- A dtor called" << endl; }
#ifndef WORKAROUND1
operator B() {
cout << "-- Class A -> Class B conversion called" << endl;
B b1;
return b1;
}
#endif
};
#ifdef WORKAROUND2
void test(const B &b)
#else
void test(B b)
#endif
{
cout << "-- Calling function test(B) on B: " << (long)(&b) << endl;
}
int main()
{
A a;
#ifdef WORKAROUND3
B b(a);
test(b);
#else
test(a);
#endif
return 0;
}
Additional query words: 1.00 1.50 1.51 1.52 2.00 2.10 8.0 8.00 8.0c 8.00c 9.0 9.00 GPF
Keywords: kbbug kbfix KB129617