c++ - understanding operator lookup; which compiler is correct? -
Previously asked, but I did not have the luck to get the answer ...
I An uneded container (i.e. hash; we call it que hash because it is probably in any similar situation) whose key type requires an operator operator.
Consider the following:
// foo.h class bar {public: square fu {}; }; // foo.cpp # include & lt; QtCore / QHash & gt; Namespace {typedef Bar :: Foo Foo; Bull Operator == (Fu Conste & A, Fu Conste & B) {Return & A = A and B; }} UIT qHash (Foo const & amp; foo) {return qHash (& amp; foo); } Int main () {QUTS & Lt; Foo, Int, & gt; Hash; // stuff with hash, e.g., hash.incent (foo (), 5); Return 0; }
Using G ++, all right. However, the error lies in the intestinal error of qhash.h about
. I feel that the rings do not have to find or deny the definition of the binary expression to the invalid operands
where ==
trying to use < Code> foo operator ==
in the anonymous namespace, probably due to different lookup rules compared to G ++.
I'm thinking, which compiler is right?
ps is building in C ++ 11 mode, if there is a difference in it.
Well, look at ADL [basic .lookup.argdep] / 2: "Every argument in the function call For type T, there is a set of zero or more associated namespaces and a set of zero or more related sections are considered. By setting types of namespaces and squares of arguments (and namespace of any template template argument) Are fully determined. Typedef names and types are not Usage announcements do not contribute to this set for specifying.
Focus on the last sentence.
So, for the original example, the operator's namespace was typed in F Does not help, the GCC is wrong and the quarrel is right.
Comments
Post a Comment