久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

C++ 模板的兩階段名稱查找 - 為什么?

Two phase name lookup for C++ templates - Why?(C++ 模板的兩階段名稱查找 - 為什么?)
本文介紹了C++ 模板的兩階段名稱查找 - 為什么?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

限時送ChatGPT賬號..

為什么 C++ 標(biāo)準(zhǔn)為模板定義了兩階段查找?非依賴聲明和定義的查找不能也推遲到實例化階段嗎?

Why does the C++ standard define two phase lookup for templates? Couldn't non dependent declarations and definitions' lookups be deferred to the instantiation stage as well?

推薦答案

他們可以.這是最早期的模板實現(xiàn)方式工作,并且仍然是 Microsoft 編譯器的工作方式.有人感覺到(在委員會中)這太容易出錯了;這太容易了不小心劫持了一個名字,在一個翻譯中實例化unit 選擇一個本地名稱,而不是所需的全局符號.(一個典型的翻譯單元將由一系列 #include 組成,聲明每個人都應(yīng)該看到的名稱,然后是實現(xiàn)代碼.在實例化點之前的所有東西實例化是可見的,包括實現(xiàn)代碼.)

They could. This is the way most early implementations of templates worked, and is still the way the Microsoft compiler worked. It was felt (in the committee) that this was too error prone; it made it too easy to accidentally hijack a name, with the instantiation in one translation unit picking up a local name, rather than the desired global symbol. (A typical translation unit will consist of a sequence of #includes, declaring the names that everyone should see, followed by implementation code. At the point of instantiation, everything preceding the point of instantation is visible, including implementation code.)

最終決定是將模板中的符號分為兩類類別:依賴和非依賴,并堅持認(rèn)為非依賴符號在定義時解析模板,以減少它們意外綁定到某些本地實現(xiàn)符號.加上要求指定typenametemplate 當(dāng)適用于依賴符號時,這個還允許在定義點進(jìn)行解析和一些錯誤檢查模板,而不是僅在模板實例化時.

The final decision was to classify the symbols in a template into two categories: dependent and non-dependent, and to insist that the non-dependent symbols be resolved at the point of definition of the template, to reduce the risk of them accidentally being bound to some local implementation symbols. Coupled with the requirement to specify typename and template when appropriate for dependent symbols, this also allows parsing and some error checking at the point of definition of the template, rather than only when the template is instantiated.

這篇關(guān)于C++ 模板的兩階段名稱查找 - 為什么?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Difference between std::reference_wrapper and simple pointer?(std::reference_wrapper 和簡單指針的區(qū)別?)
Difference between const. pointer and reference?(常量之間的區(qū)別.指針和引用?)
How to access the contents of a vector from a pointer to the vector in C++?(c++ - 如何從指向向量的指針訪問向量的內(nèi)容?)
Meaning of *amp; and **amp; in C++(*amp; 的含義和**amp;在 C++ 中)
Why can#39;t I do polymorphism with normal variables?(為什么我不能對普通變量進(jìn)行多態(tài)?)
Dereferencing deleted pointers always result in an Access Violation?(取消引用已刪除的指針總是會導(dǎo)致訪問沖突?)
主站蜘蛛池模板: 免费h在线| 午夜噜噜噜 | 久久久久国产一区二区三区四区 | 国产小网站| 免费在线成人 | 99精品视频一区二区三区 | 欧美久久大片 | 免费在线性爱视频 | 亚洲精品日韩精品 | 日韩一区不卡 | 精品一区在线免费观看 | 91精品国产综合久久久久久漫画 | 欧美精品二区三区 | 西西裸体做爰视频 | 免费成年网站 | 一本一道久久a久久精品综合蜜臀 | av免费成人 | 国产免费一区二区三区 | 国产精品久久在线 | 午夜电影网站 | 天天躁日日躁狠狠躁2018小说 | 日韩视频区 | 国产日韩一区二区三免费高清 | 亚洲国产精品一区 | 一区二区三区四区av | 日本一卡精品视频免费 | 国产一级淫片a直接免费看 免费a网站 | 黄色国产视频 | 精品一级 | 国产玖玖 | 午夜私人影院在线观看 | 国产精品国产三级国产aⅴ原创 | 在线色网址| 欧美色综合 | 精品国产乱码久久久久久丨区2区 | 精品伊人久久 | 国产精品亚洲综合 | 亚洲日日夜夜 | www.久久99 | 久久99精品久久 | av免费网站在线观看 |