PSS ID Number: 116239
Article Last Modified on 10/16/2002
A int () }
^ ^
/ \
/ \
B { int () } C {}
^ ^
\ /
\ /
E { }
The dominance rule requires that when you invoke the virtual user-defined
conversion function to int from an instance of an object of type E, the
version provided by B should be used. This conversion function may be
invoked implicitly by assigning an instance of an object of type E to an
int. It may also be invoked explicitly through the use of the "operator
int" function.
/* Compile options needed: /W3
*/
#include <iostream.h>
class A
{
public:
virtual operator int () { return 2; }
};
class B : virtual public A
{
public:
virtual operator int () { return 3; }
};
class C : virtual public A {};
class E : public B, public C {};
void main(void)
{
int i;
int error=0;
E eObject;
// Both of the invocations below should call B's
// operator int ().
if ((i = eObject) != 3) // Fails to compile
error = 1;
if ((i = eObject.operator int()) != 3) // Compiles OK
error = 1;
if (!error)
cout << "PASSED" << endl;
else
cout << "FAILED" << endl;
}
Additional query words: kbVC400bug 8.00 8.00c 9.00
Keywords: kbBug kbCompiler kbCPPonly KB116239
Technology: kbAudDeveloper kbCVCComp kbvc100 kbvc150 kbVC200 kbVC32bitSearch kbVC400 kbVC410 kbVC420 kbVC500 kbVC500Search kbVC600 kbVCNET kbVCsearch kbZNotKeyword3 kbZNotKeyword8