M
miguel.a.guedes
Hello everyone,
Please consider the following bit of code:
namespace x
{
class X
{
public:
X(){}
~X(){}
void set(int a) {i=a;}
int i;
};
}
x::X X;
int _tmain(int argc, _TCHAR* argv[])
{
using namespace x; // commenting this out shuts up the compiler's
whining
X.set(4); // error C2872: 'X' : ambiguous symbol
// could be 'c:\temp\test\test\test\test.cpp(27) : x::X X'
// or 'c:\temp\test\test\test\test.cpp(18) : x::X'
}
Isn't the compiler supposed to automatically resolve the ambiguity
since X.set(4) refers to *instance X* and not class X? In fact, I
don't see any ambiguity whatsoever. X.set(4) clearly refers to
'instance X' and not abstract type X, as that would implicate using
the operator '::'.
What do the standards say on this?
PS: I think I'm just gonna have to go back to prefixing every class
name with some letter. I can't afford to be bothered with these stupid
puzzles involving ridiculous ambiguities!
Please consider the following bit of code:
namespace x
{
class X
{
public:
X(){}
~X(){}
void set(int a) {i=a;}
int i;
};
}
x::X X;
int _tmain(int argc, _TCHAR* argv[])
{
using namespace x; // commenting this out shuts up the compiler's
whining
X.set(4); // error C2872: 'X' : ambiguous symbol
// could be 'c:\temp\test\test\test\test.cpp(27) : x::X X'
// or 'c:\temp\test\test\test\test.cpp(18) : x::X'
}
Isn't the compiler supposed to automatically resolve the ambiguity
since X.set(4) refers to *instance X* and not class X? In fact, I
don't see any ambiguity whatsoever. X.set(4) clearly refers to
'instance X' and not abstract type X, as that would implicate using
the operator '::'.
What do the standards say on this?
PS: I think I'm just gonna have to go back to prefixing every class
name with some letter. I can't afford to be bothered with these stupid
puzzles involving ridiculous ambiguities!