Why does C++11 not support name lookup like this? [closed]

♀尐吖头ヾ 提交于 2019-12-05 10:22:46

Function calls in C++ are subject to function overload resolution. Overload resolution is driven by the argument types. I.e. the language "works" specifically in that direction: from argument types to specific version of the function with the given name.

You are proposing to introduce a reverse process - argument type deduction based on function name. This will not work in general case. It might work in cases when there's only one candidate function (as in your example), but, again, in is contrary to principles that work in the general situation when the function is overloaded.

Of course, the situation will get even more complicated when name lookup on unqualified name X can see something else named X in addition to your A::X. I think it can easily get very counterintuitive.

I think the ADL rule should be generalized to such a case.

No thank you.

C++ has its share of (nasty) surprises (which other language do you know requires explicit as a keyword?), and I don't see enough merit in your example to add to this list of unexpected language rules hindering my code in unexpected situations.

If you find the additional typing entailed in class-name followed by the two colons as too much effort, then surely the general baroque nature of C++ syntax should have put you off by now?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!