Topic: name lookup in class scope occurs ambiguity , it's very strange.


Author: cpu-g@yahoo.com.tw
Date: Sun, 7 Oct 2007 12:56:55 CST
Raw View
#include<iostream>
using namespace std;

struct A
{
 int a;
};

struct B1:public A
{
 int a;
 B1(){a=1;A::a=11;}
};

struct B2:public A
{
 int a;
 B2(){a=2;A::a=22;}
};

struct C :public B1,public B2
{
  void foo()
  {
    cout<<C::B1::A::a; //ambiguous, vc8 is ok, 11
    cout<<C::B2::A::a; //ambiguous, vc8 is ok, 22
    cout<<C::B1::a;    //ok. 1
    cout<<C::B2::a;    //ok. 2
  }
};

why many compiler(g++/comeau/ICC) I test occurs
ambiguity ? Only vc8 compiler can work.

the access style(C::B1::A::a or C::B2::A::a) fits
people's intuition.

I want to know if the part of ambiguity conforms to
ISO C++ Standard.


Thanks for your responce.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]