An answer to this question says in the following code:
#include <vector>
using std::vector;
struct foo {
template<typename U>
void vector();
};
int main() {
foo f;
f.vector<int>(); // ambiguous!
}
The last line in main is ambiguous, because the compiler not only looks up vector
within foo
, but also as an unqualified name starting from within main
. So it finds both std::vector
and foo::vector
. To fix this, you have to write
f.foo::vector<int>();
I've tried this program on all popular C++ compilers ( g++
, clang++
, vc++
and Intel C++ ) and all compilers compile this program without any error. So, why did he say that there is ambiguity in this program ? What does the C++ standard say about this ?