c – 3.4.2 n3290草稿中的参数相关名称查找

c – 3.4.2 n3290草稿中的参数相关名称查找,第1张

概述来自ISO草案n3290第3.4.2段第1段: When the postfix-expression in a function call is an unqualified-id, other namespaces not considered during the usual unqualified lookup may be searched, and in those namespace 来自ISO草案n3290第3.4.2段第1段:

When the postfix-Expression@H_419_5@ in a function call is an unqualifIEd-ID@H_419_5@,other namespaces not consIDered during the usual unqualifIEd lookup may be searched,and in those namespaces,namespace-scope frIEnd function declarations not otherwise visible may be found. These modifications to the search depend on the types of the arguments (and for template template arguments,the namespace of the template argument).

在这里他们说,“这些对搜索的修改取决于参数/模板模板参数/模板参数的命名空间的类型”…可以有任何一个具有示例的expalin吗?我尝试用argumetn类型.使用模板模板参数类型&模板参数类型的命名空间

解决方法 考虑一个简单的不合格的函数调用:
foo(x);

ADL意味着foo不仅在封闭的范围内查找,而且调用所在的命名空间也被查找,而且也是x类型的命名空间.例如如果x是一个std :: vector< int>那么还会搜索namespace std.从而:

int main() {    std::vector<int> x,y;    swap(x,y);}

可以,并调用std :: swap().

查找也取决于任何模板参数的命名空间,因此如果x是std :: vector< mynamespace :: myclass>那么mynamespace也包含在查找中.从而

namespace mynamespace {    struct myclass {};    voID foo(std::vector<mynamespace::myclass> const&){}}int main() {    std::vector<mynamespace::myclass> x;    foo(x);}

会调用mynamespace :: foo().

最后,查找也扩展到用作模板模板参数的任何模板的命名空间.例如

namespace mynamespace {    template<typename T>    struct mytemplate    {};    template<typename T>    voID bar(T const&) {}}template<template<typename> class T>struct wrapper {};int main() {    wrapper<mynamespace::mytemplate> x;    bar(x);}

即使包装器在全局命名空间中,将会找到mynamespace :: bar,因为用于x的模板模板参数是mynamespace :: mytemplate.

总结

以上是内存溢出为你收集整理的c – 3.4.2 n3290草稿中的参数相关名称查找全部内容,希望文章能够帮你解决c – 3.4.2 n3290草稿中的参数相关名称查找所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1249794.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-07
下一篇 2022-06-07

发表评论

登录后才能评论

评论列表(0条)