Example of Resolving Ambiguous Access


/************************************************************************
*

The following example uses the :: (scope resolution) operator to resolve an ambiguous reference.

                                                                        *
************************************************************************/

// This example illustrates ambiguous base classes.

class B1
{
public:
      int i;
      int j;
      int g( );
};
class B2
{
public:
      int j;
      int g( );
};
// ...
class D : public B1, public B2
{
public:
      int i;
};
void main ()
{
      D dobj;
      D *dptr = &dobj;
      dptr -> i = 5;        // valid, D::i
      dptr -> j = 10;       // error, ambiguous reference to j
      dptr->B1::j = 10;     // valid, B1::j
      dobj.g( );            // error, ambiguous reference to g( )
      dobj.B2::g( );        // valid, B2::g( )
}