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

如何在類中創(chuàng)建模板函數(shù)?(C++)

How to create a template function within a class? (C++)(如何在類中創(chuàng)建模板函數(shù)?(C++))
本文介紹了如何在類中創(chuàng)建模板函數(shù)?(C++)的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我知道可以制作模板函數(shù):

I know it's possible to make a template function:

template<typename T>
void DoSomeThing(T x){}

并且可以制作模板類:

template<typename T>
class Object
{
public:
    int x;
};

但是是否可以在模板中創(chuàng)建一個類,然后將那個類中的函數(shù)創(chuàng)建為模板?即:

but is it possible to make a class not within a template, and then make a function in that class a template? Ie:

//I have no idea if this is right, this is just how I think it would look
class Object
{
public:
    template<class T>
    void DoX(){}
};

或者在某種程度上,類不是模板的一部分,但函數(shù)是?

or something to the extent, where the class is not part of a template, but the function is?

推薦答案

你的猜測是正確的.你唯一需要記住的是成員函數(shù)模板定義(除了聲明)應(yīng)該在頭文件中,而不是cpp中,盡管它不是必須在類聲明本身的主體中.

Your guess is the correct one. The only thing you have to remember is that the member function template definition (in addition to the declaration) should be in the header file, not the cpp, though it does not have to be in the body of the class declaration itself.

這篇關(guān)于如何在類中創(chuàng)建模板函數(shù)?(C++)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

How can I read and manipulate CSV file data in C++?(如何在 C++ 中讀取和操作 CSV 文件數(shù)據(jù)?)
In C++ why can#39;t I write a for() loop like this: for( int i = 1, double i2 = 0; (在 C++ 中,為什么我不能像這樣編寫 for() 循環(huán): for( int i = 1, double i2 = 0;)
How does OpenMP handle nested loops?(OpenMP 如何處理嵌套循環(huán)?)
Reusing thread in loop c++(在循環(huán) C++ 中重用線程)
Precise thread sleep needed. Max 1ms error(需要精確的線程睡眠.最大 1ms 誤差)
Is there ever a need for a quot;do {...} while ( )quot; loop?(是否需要“do {...} while ()?環(huán)形?)
主站蜘蛛池模板: 久久久久9999 | 久久久久www | 亚洲成人久久久 | 在线视频一区二区三区 | 国产一区二 | 99视频在线 | 亚洲精品久久久久久宅男 | 精品久久久久久久久久久院品网 | 精品视频在线播放 | 色天堂视频 | 成人久久| 亚洲九九精品 | 欧美欧美欧美 | 成人黄色电影免费 | 免费黄色日本 | 伊人网综合在线观看 | 精品久久久久一区二区国产 | 最新中文字幕一区 | 免费特黄视频 | 日韩欧美在线观看一区 | 亚洲一区久久 | 久久久久久久国产 | 日本精品视频 | 99爱国产| 午夜99| 免费能直接在线观看黄的视频 | 国产高清视频一区二区 | 久久精品亚洲精品国产欧美 | 91精品国产一区二区三区 | 亚洲图片一区二区三区 | 国产成人精品久久二区二区91 | 国产日韩亚洲欧美 | 亚洲欧美在线一区 | 求毛片| 午夜久久久 | 高清国产一区二区 | 天天天天操 | 欧美中国少妇xxx性高请视频 | 美女久久久久 | 日韩资源 | 精品成人av|