久久久久久久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?(取消引用已刪除的指針總是會導致訪問沖突?)
主站蜘蛛池模板: av在线免费观看网址 | 日韩福利 | 日韩精品视频一区二区三区 | 日韩中文字幕一区二区 | 999国产精品视频免费 | 日韩一区二区免费视频 | 精品视频一区二区三区在线观看 | 国产欧美精品一区二区色综合朱莉 | 欧美精品网站 | 色资源站| 亚洲伊人久久综合 | 国产精品久久久久久久久久久久久 | 欧美精品一区在线发布 | 亚洲网在线 | 日韩1区 | 色黄网站 | 玖玖操| 久久久久久久久久久一区二区 | 久久婷婷国产 | 成人一区二区三区在线观看 | 精品一区二区三区91 | 黄色毛片大全 | 亚洲一区中文字幕在线观看 | 黄视频欧美| 中文字幕成人免费视频 | 成人精品在线视频 | 黄色国产在线播放 | 中文av电影| 一区二区三区免费在线观看 | 一级aaaa毛片 | 在线91| 东京av男人的天堂 | 精品免费视频 | 久久一及片 | 国产三区视频在线观看 | 91麻豆精品国产91久久久更新资源速度超快 | 人妖一区 | 亚洲成人免费av | 久久久国产精品 | 久久激情网| 一区二区伦理电影 |