3
爲什麼using ::foo
聲明下面隱藏了所有其他foo
函數?C++使用聲明
#include <iostream>
void foo(double) { std::cout << "::foo(double)" << std::endl; }
struct A {
void foo(float) { std::cout << "A::foo(float)" << std::endl; }
void foo(int) { std::cout << "A::foo(int)" << std::endl; }
void foo() { std::cout << "A::foo()" << std::endl; }
};
struct B : A {
using A::foo;
void foo(int) { std::cout << "B::foo(int)" << std::endl; }
void foo() { std::cout << "B::foo()" << std::endl; }
void boo() {
using ::foo;
foo(1.0);
foo(1.0f);
foo(1);
foo();
};
};
int main() {
B b;
b.boo();
return 0;
}
這是在copy-swap成語中用於'std :: swap'的ADL查找。 http://stackoverflow.com/questions/4782692/what-does-using-stdswap-inside-the-body-of-a-class-method-implementation-mea – Brandon
好的,但爲什麼B :: foo()不可訪問? –
@BlazBratanic不是,你嘗試過'B :: foo()'嗎? – yizzlez