I cannot understand why this piece of code does not compile:
namespace A {
class F {}; // line 2
class H : public F {};
}
namespace B {
void F(A::H x); // line 7
void G(A::H x) {
F(x); // line 9
}
}
I am using gcc 4.3.3, and the error is:
s3.cpp: In function ‘void B::G(A::H)’:
s3.cpp:2: error: ‘class A::F’ is not a function,
s3.cpp:7: error: conflict with ‘void B::F(A::H)’
s3.cpp:9: error: in call to ‘F’
I think that because in line 9 there is no namespace prefix, F(x) should definitively mean only B::F(x). The compiler tries to cast x into its own superclass. In my understanding it should not. Why does it do that?
That’s because compiler will search function in the same namespace its arguments from. Compiler found there
A::Fidentifier but it is not a function. In result you’ll get the error.It is standard behaviour as far as I can remember.
This rule allows you to write the following code:
And finally: Because of Core Issue 218 some compilers would compile the code in question without any errors.