I am pretty sure it is a bug in VS 2010, but it’s always a good idea to check on SO
struct A{
static int s;
};
struct B{
static int s;
};
struct C : A, B{
void fn(short s){ // Ambiguous access of 's' here!!!
s = 2;
}
};
int A::s;
int B::s;
int main(){
C c;
}
VS gives- “error C2385: ambiguous access of ‘s'”.
g++ and Comeau compile fine.
Am I missing something?
Visual C++ is worried about the diamond problem- the instance member named “s” is ambiguous due to diamond-shaped inheritance. But here, it should be shadowed by the local parameter named “s”, so there’s nothing illegal about this code. It should compile cleanly, unless you have something weird set in your environment to make Visual C++ complain about shadowed variable names.