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

C++ 模板只是偽裝的宏嗎?

Are C++ Templates just Macros in disguise?(C++ 模板只是偽裝的宏嗎?)
本文介紹了C++ 模板只是偽裝的宏嗎?的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

限時(shí)送ChatGPT賬號(hào)..

我已經(jīng)用 C++ 編程幾年了,我已經(jīng)使用了很多 STL 并且創(chuàng)建了幾次我自己的模板類來(lái)看看它是如何完成的.

I've been programming in C++ for a few years, and I've used STL quite a bit and have created my own template classes a few times to see how it's done.

現(xiàn)在我正在嘗試將模板更深入地集成到我的 OO 設(shè)計(jì)中,一個(gè)煩人的想法不斷回到我的腦海中:它們只是一個(gè)宏,真的......你可以使用 #defines 實(shí)現(xiàn)(相當(dāng)丑陋)auto_ptrs,如果你真的想要.

Now I'm trying to integrate templates deeper into my OO design, and a nagging thought keeps coming back to me: They're just a macros, really... You could implement (rather UGLY) auto_ptrs using #defines, if you really wanted to.

這種對(duì)模板的思考方式幫助我理解我的代碼實(shí)際上是如何工作的,但我覺(jué)得我一定是在某種程度上忽略了這一點(diǎn).宏是邪惡的化身,但模板元編程"風(fēng)靡一時(shí).

This way of thinking about templates helps me understand how my code will actually work, but I feel that I must be missing the point somehow. Macros are meant evil incarnate, yet "template metaprogramming" is all the rage.

那么,真正的區(qū)別是什么?以及模板如何避免#define 導(dǎo)致的危險(xiǎn),例如

So, what ARE the real distinctions? and how can templates avoid the dangers that #define leads you into, like

  • 難以理解的編譯器錯(cuò)誤您不希望它們出現(xiàn)的地方?
  • 代碼膨脹?
  • 難以跟蹤代碼?
  • 設(shè)置調(diào)試器斷點(diǎn)?

推薦答案

宏是一種文本替換機(jī)制.

Macros are a text substitution mechanism.

模板是一種功能圖靈完備的語(yǔ)言,在編譯時(shí)執(zhí)行并集成到 C++ 類型系統(tǒng)中.您可以將它們視為語(yǔ)言的插件機(jī)制.

Templates are a functional turing-complete language that is executed at compile time and is integrated into the C++ type system. You can think of them as a plugin mechanism for the language.

這篇關(guān)于C++ 模板只是偽裝的宏嗎?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

Difference between std::reference_wrapper and simple pointer?(std::reference_wrapper 和簡(jiǎn)單指針的區(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++ - 如何從指向向量的指針訪問(wèn)向量的內(nèi)容?)
Meaning of *amp; and **amp; in C++(*amp; 的含義和**amp;在 C++ 中)
Why can#39;t I do polymorphism with normal variables?(為什么我不能對(duì)普通變量進(jìn)行多態(tài)?)
Dereferencing deleted pointers always result in an Access Violation?(取消引用已刪除的指針總是會(huì)導(dǎo)致訪問(wèn)沖突?)
主站蜘蛛池模板: 一区二区三区精品视频 | 91免费福利视频 | av天天干 | 免费观看的黄色网址 | av在线播放一区二区 | 久久国产电影 | 看片地址 | 欧美一区二区三区免费在线观看 | 国产精品久久久久久久久久了 | 成人一区二区视频 | 美女张开腿露出尿口 | 亚洲狠狠爱 | 国产黄色在线 | 久久久久久久国产精品视频 | 日韩精品在线视频 | wwww.xxxx免费 | 91资源在线 | 伊人在线 | 日韩精品一区二区三区中文在线 | 日韩在线视频观看 | 91精品久久久久久久久久入口 | 欧美日韩精品久久久免费观看 | 啪一啪| 亚洲九色 | 在线国产视频 | 国产91久久久久蜜臀青青天草二 | 日本黄色一级片视频 | 日韩久久精品电影 | 欧美成人免费在线视频 | 国产91久久久久蜜臀青青天草二 | 国产污视频在线 | 色婷婷av一区二区三区软件 | 久久精品久久久久久 | 激情五月激情综合网 | 成年人网站免费 | www天天操 | 久久av一区二区三区 | 国产精品免费在线 | 91成人精品视频 | 国产精品美女在线观看 | 国产91 在线播放 |