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

模板類特化,其中模板參數是模板

Templated class specialization where template argument is a template(模板類特化,其中模板參數是模板)
本文介紹了模板類特化,其中模板參數是模板的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我想知道是否有可能發生類似的事情.基本上,我有一個模板化類,它偶爾會使用模板化類的對象.我想將它(或只是一個成員函數)專門用于特定的模板化類,但是該類的通用"形式.

I wondering if something similar to this is possible. Basically, I have a templated class that occasionally takes objects of templated classes. I would like to specialize it (or just a member function)for a specific templated class, but the 'generic' form of that class.

template<typename T, typename S>
class SomeRandomClass
{
    //put something here
};

template<typename T>
class MyTemplateClass
{
    void DoSomething(T & t) {
       //...something
    }
};

template<>
void MyTemplateClass< SomeRandomClass<???> >::DoSomething(SomeRandomClass<???> & t)
{
    //something specialized happens here
}

用適當的類型(double 等)替換問號是可行的,但我希望它保持通用.我不知道該放什么,因為沒有定義任何類型.我環顧四周,了解了模板模板參數,并嘗試了各種組合都無濟于事.感謝您的幫助!

Replacing the question marks with appropriate types (double, etc) works, but I would like it to remain generic. I don't know what to put there, as any types wouldn't have been defined. I've looked around, and learned about template template parameters, and tried various combinations to no avail. Thanks for the help!

推薦答案

可以像這樣專門化類

template <>
template <typename T,typename S>
class MyTemplateClass <SomeRandomClass<T,S> >
{
    void DoSomething(SomeRandomClass<T,S>& t) { /* something */ }
};

只對成員方法進行特化是不可能的,因為特化是針對整個類的,您必須定義一個新類.但是,您可以這樣做

It's not possible to specialize just the member method, because the specialization is on the class as a whole, and you have to define a new class. You can, however, do

template <>
template <typename T,typename S>
class MyTemplateClass <SomeRandomClass<T,S> >
{
    void DoSomething(SomeRandomClass<T,S>& t);
};

template <>
template <typename T,typename S>
void MyTemplateClass<SomeRandomClass<T,S> >::DoSomething(SomeRandomClass<T,S>& t)
{
    // something
}

拆分聲明和定義.

這篇關于模板類特化,其中模板參數是模板的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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?(取消引用已刪除的指針總是會導致訪問沖突?)
主站蜘蛛池模板: 国产98色在线 | 日韩 | 麻豆精品久久久 | 99热视| 国产在线中文字幕 | 久久精品国产99国产精品 | 天天操天天插 | 97国产爽爽爽久久久 | 日韩中文字幕av | 亚洲免费精品 | 国产精品久久久久久久久久久久久 | 色网在线观看 | 欧美性大战久久久久久久蜜臀 | 久久免费国产 | 久久亚洲一区二区三区四区 | av在线黄 | 国产一区二区 | 在线免费91 | 久久精品亚洲国产奇米99 | 国产一区二区视频免费在线观看 | 综合久久99| 日本免费黄色 | 欧美一区二区三区久久精品 | 97精品超碰一区二区三区 | 国产成人午夜精品影院游乐网 | 亚洲日韩欧美一区二区在线 | 欧美三级三级三级爽爽爽 | 免费黄色的视频 | 免费在线a视频 | 午夜国产精品视频 | 亚洲国产精品一区二区久久 | 欧美在线一区二区三区 | 日本一区二区高清不卡 | 欧美日本亚洲 | 国产美女永久免费无遮挡 | 国产精品日日做人人爱 | 日韩欧美国产精品一区 | 黄网站免费在线 | 国产黄色av网站 | 亚洲视频中文字幕 | 午夜a区 | 99re国产 |