中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當(dāng)前位置: 首頁 > news >正文

網(wǎng)站做任務(wù)掙錢鄭州seo優(yōu)化外包顧問阿亮

網(wǎng)站做任務(wù)掙錢,鄭州seo優(yōu)化外包顧問阿亮,用php做醫(yī)藥網(wǎng)站開題報告,建站之星官網(wǎng)登陸當(dāng)編寫一個模板特化,涉及部分但不是全部模板參數(shù)時,它被稱為偏特化(Partial Specialization)?!咀⒁?amp;#xff0c;偏特化是針對類模板而言,函數(shù)模板不可偏特化,只能全特化】 偏特化是C模板編程中的一種技術(shù)…

當(dāng)編寫一個模板特化,涉及部分但不是全部模板參數(shù)時,它被稱為偏特化(Partial Specialization)?!咀⒁?#xff0c;偏特化是針對類模板而言,函數(shù)模板不可偏特化,只能全特化】
偏特化是C++模板編程中的一種技術(shù),允許為特定類型或特定類型組合的模板參數(shù)創(chuàng)建專門的模板定義。這使得可以根據(jù)模板參數(shù)的特定屬性或組合來定制模板的行為,從而提供更靈活和定制化的解決方案。

在偏特化中,可以保留模板參數(shù)中的一部分,而將另一部分替換為特定的類型或模式。這使得可以為不同的參數(shù)提供不同的實(shí)現(xiàn),以滿足特定的需求或條件。

偏特化在處理復(fù)雜的模板類型時特別有用,例如嵌套模板或帶有多個模板參數(shù)的模板。通過偏特化可以根據(jù)具體情況對模板進(jìn)行定制,而無需完全重新實(shí)現(xiàn)整個模板。

總的來說,偏特化是C++模板編程中的一項(xiàng)重要技術(shù),允許根據(jù)特定的模板參數(shù)定制模板的行為,從而提供更靈活和高效的解決方案。

開始偏特化時,使用一個模板頭列出沒有特化的模板參數(shù),然后定義特化。與完全特化一樣,通過列出所有模板參數(shù)來命名要特化的類。一些模板參數(shù)取決于特化的參數(shù),而另一些則使用特定值。

與完全特化一樣,特化的定義完全替換了特定一組模板參數(shù)的主模板。按照慣例,保持相同的接口,但實(shí)際的實(shí)現(xiàn)不要求與原始模板一致。

偏特化示例:

#include <iostream>
#include <vector>/* 1. 原始模板 */
template<class T, class U>
class Rational{
public:// Delegating ConstructorRational(): Rational(0){std::cout << __PRETTY_FUNCTION__ << std::endl;}Rational(T num): numerator_(num), denominator_(1){std::cout << __PRETTY_FUNCTION__ << std::endl;}Rational(T num, U den): numerator_(num), denominator_(den){std::cout << __PRETTY_FUNCTION__ << std::endl;}virtual ~Rational(){std::cout << __PRETTY_FUNCTION__ << std::endl;}T numerator()const{return numerator_;}U denominator()const{return denominator_;}template<class V>V calculate();private:T numerator_;U denominator_;
};template<class T, class U>
template<class V>
V Rational<T,U>::calculate(){return static_cast<V>(numerator_) / static_cast<V>(denominator_);  // omit divided by zero
}/* 2. Partial Specialization,特化U為float */
template<class T>
class Rational<T, float>{
public:// Delegating ConstructorRational(): Rational(0){std::cout << __PRETTY_FUNCTION__ << std::endl;}Rational(T num): numerator_(num), denominator_(1){std::cout << __PRETTY_FUNCTION__ << std::endl;}Rational(T num, T den): numerator_(num), denominator_(den){std::cout << __PRETTY_FUNCTION__ << std::endl;}virtual ~Rational(){std::cout << __PRETTY_FUNCTION__ << std::endl;}T numerator()const{return numerator_;}float denominator()const{return denominator_;}template<class V>V calculate();private:T numerator_;float denominator_;
};template<class T>
template<class V>
V Rational<T,float>::calculate(){return static_cast<V>(numerator_) / static_cast<V>(denominator_);  // omit divided by zero
}/* 3. Partial Specialization,特化T為float */
template<class U>
class Rational<float,U>{
public:// Delegating ConstructorRational(): Rational(0){std::cout << __PRETTY_FUNCTION__ << std::endl;}Rational(float num): numerator_(num), denominator_(1){std::cout << __PRETTY_FUNCTION__ << std::endl;}Rational(float num, U den): numerator_(num), denominator_(den){std::cout << __PRETTY_FUNCTION__ << std::endl;}virtual ~Rational(){std::cout << __PRETTY_FUNCTION__ << std::endl;}float numerator()const{return numerator_;}U denominator()const{return denominator_;}template<class V>V calculate();private:float numerator_;U denominator_;
};template<class U>
template<class V>
V Rational<float,U>::calculate(){return static_cast<V>(numerator_) / static_cast<V>(denominator_);  // omit divided by zero
}int main() {Rational<float,int> r1;Rational<int,float> r2;Rational<int,int> r3;Rational<double,double> r4;//Rational<float,float> r5;  // 此句報錯error: ambiguous template instantiation for 'class Rational<float, float>'
}
http://www.risenshineclean.com/news/49133.html

相關(guān)文章:

  • 十堰h(yuǎn)5網(wǎng)站建設(shè)全球搜鉆是什么公司
  • 畢業(yè)設(shè)計網(wǎng)站前端代做關(guān)鍵詞seo優(yōu)化公司
  • 可以自己買個服務(wù)器做網(wǎng)站嗎自助建站系統(tǒng)模板
  • 南充城市建設(shè)投訴網(wǎng)站百度如何注冊公司網(wǎng)站
  • 公司展廳設(shè)計策劃優(yōu)化網(wǎng)站視頻
  • 企業(yè)快速建站都有哪些技巧呢seo免費(fèi)優(yōu)化工具
  • 在線網(wǎng)站轉(zhuǎn)app深圳seo優(yōu)化推廣公司
  • ipv6跟做網(wǎng)站有關(guān)嗎培訓(xùn)心得體會100字
  • 網(wǎng)站建設(shè)濟(jì)南有做的嗎他達(dá)拉非片和偉哥區(qū)別
  • 網(wǎng)站開始開發(fā)階段的主要任務(wù)提供seo顧問服務(wù)適合的對象是
  • 大學(xué)生心里健康網(wǎng)站設(shè)計與建設(shè)自助建站系統(tǒng)哪個好用
  • 怎么建設(shè)微信網(wǎng)站南寧百度推廣seo
  • 二級域名著名網(wǎng)站logo網(wǎng)站設(shè)計
  • 建設(shè)企業(yè)網(wǎng)站多少錢全國網(wǎng)站排名
  • b2b2c電商平臺開發(fā)長沙seo外包平臺
  • 做網(wǎng)站那里好名站在線
  • wordpress 畫廊 插件西安做推廣優(yōu)化的公司
  • 自己做網(wǎng)站還能掙錢嗎2023年6月份又封城了
  • 手機(jī)wap購物網(wǎng)站模板seo排名優(yōu)化推薦
  • 新的網(wǎng)站建設(shè)技術(shù)方案東莞企業(yè)網(wǎng)站設(shè)計公司
  • wordpress建立商城杭州關(guān)鍵詞優(yōu)化平臺
  • 通過ip訪問網(wǎng)站需要怎么做詞愛站的關(guān)鍵詞
  • 免費(fèi)b站推廣網(wǎng)站不用下載長沙網(wǎng)站托管seo優(yōu)化公司
  • 1.1做網(wǎng)站的目的一個新產(chǎn)品的營銷方案
  • 做網(wǎng)站賺錢嗎免費(fèi)數(shù)據(jù)查詢網(wǎng)站
  • 做app網(wǎng)站的公司seo關(guān)鍵詞排名技巧
  • 瀘州網(wǎng)站建設(shè)北京網(wǎng)站建設(shè)優(yōu)化
  • 網(wǎng)站建設(shè)需要政府集中采購嗎免費(fèi)廣告投放網(wǎng)站
  • 網(wǎng)站怎么上傳數(shù)據(jù)庫淺議網(wǎng)絡(luò)營銷論文
  • 網(wǎng)站創(chuàng)作情感營銷