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

C++模板中實例化和特化的區別

Difference between instantiation and specialization in c++ templates(C++模板中實例化和特化的區別)
本文介紹了C++模板中實例化和特化的區別的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

C++ 模板上下文中的特化和實例化有什么區別.根據我目前閱讀的內容,以下是我對特化和實例化的理解.

What is the difference between specialization and instantiation in context of C++ templates. From what I have read so far the following is what I have understood about specialization and instantiation.

template <typename T>
struct Struct
{

     T x;
};

template<>
struct Struct <int> //specialization
{

    //code
};

int main()
{
   Struct <int> s; //specialized version comes into play
   Struct <float> r; // Struct <float> is instantiated by the compiler as shown below

}

編譯器對 Struct 的實例化

template <typename T=float>
struct Struct
{
    float x;
}

我對模板實例化和特化的理解是否正確?

Is my understanding of template instantiation and specialization correct?

推薦答案

(隱式)實例化

這就是您所說的實例化(如問題中所述)

(Implicit) Instantiation

This is what you refer to as instantiation (as mentioned in the Question)

這是當您告訴編譯器使用給定類型實例化模板時,如下所示:

This is when you tell the compiler to instantiate the template with given types, like this:

template Struct<char>; // used to control the PLACE where the template is inst-ed

(顯式)專業化

這就是您所說的專業化(如問題中所述)

(Explicit) Specialization

This is what you refer to as specialization (as mentioned in the Question)

這是當您為類型的子集提供模板的替代定義時,如下所示:

This is when you give an alternative definition to a template for a subset of types, like this:

template<class T> class Struct<T*> {...} // partial specialization for pointers

這篇關于C++模板中實例化和特化的區別的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

Difference between std::reference_wrapper and simple pointer?(std::reference_wrapper 和簡單指針的區別?)
Difference between const. pointer and reference?(常量之間的區別.指針和引用?)
How to access the contents of a vector from a pointer to the vector in C++?(c++ - 如何從指向向量的指針訪問向量的內容?)
Meaning of *amp; and **amp; in C++(*amp; 的含義和**amp;在 C++ 中)
Why can#39;t I do polymorphism with normal variables?(為什么我不能對普通變量進行多態?)
Dereferencing deleted pointers always result in an Access Violation?(取消引用已刪除的指針總是會導致訪問沖突?)
主站蜘蛛池模板: av一二三区 | 欧美亚洲在线视频 | 在线免费观看毛片 | 日韩精品一区二区三区在线观看 | 中文字幕成人av | 国产精品一区二区av | 久久激情视频 | 久久久久久久久久久久久久av | 国产在线视频一区 | 国产乱性 | 91视频18 | 久久久久久综合 | 成人在线视频免费观看 | 久久久久久久国产 | 日韩精品在线播放 | 色综合九九 | 国产高清自拍视频在线观看 | 日本不卡一二三 | 亚洲天堂一区二区 | 欧美福利久久 | 91国内视频在线 | 天天综合久久 | 九一视频在线观看 | 国产一级免费视频 | 国产精品亚洲第一区在线暖暖韩国 | 中文字幕在线网 | 日韩一级免费观看 | 精品无码久久久久久国产 | 99只有精品| 国产我和子的乱视频网站 | 国产永久免费 | 国产福利在线小视频 | 黄免费观看视频 | 精品日韩一区二区 | 亚洲成人免费观看 | 久久久久久国产精品 | 国产精品一区二区福利视频 | 久久久久久蜜桃一区二区 | 欧美精品久久久久久久久久 | 在线观看视频中文字幕 | 韩日在线观看视频 |