久久久久久久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?(取消引用已刪除的指針總是會導致訪問沖突?)
主站蜘蛛池模板: 精品第一页 | 羞羞在线视频 | 久久久久久久 | 蜜桃综合网 | 国产精品高潮呻吟久久 | 欧美日韩a | 日本天堂在线观看 | 成人在线免费观看网站 | 久久精品网 | 久久国产精品免费 | 久久久久久久久久久国产 | 欧美国产一区二区 | 欧美三级在线视频 | 欧美日韩综合网 | 黄色片一区二区 | 国产午夜视频在线观看 | 日本黄色免费网站 | 亚洲福利一区 | 亚洲一级在线 | 中文字幕有码在线 | 每日更新av| 免费黄色小视频 | 97国产视频| 黄色片免费看 | 欧美激情第二页 | 少妇视频网站 | av日韩精品 | 久草视频免费 | 亚洲精品午夜精品 | 国产麻豆一区二区三区 | 日本黄a三级三级三级 | 91精品久久久久久 | 久久精品日韩 | 在线观看一区 | 久久综合伊人77777蜜臀 | 日韩免费高清 | 色八区| 黄网站免费在线观看 | 日本欧美在线观看 | 欧美成在线 | 在线一区视频 |