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

如何強制 C++ 模板的特定實例進行實例化?

How do I force a particular instance of a C++ template to instantiate?(如何強制 C++ 模板的特定實例進行實例化?)
本文介紹了如何強制 C++ 模板的特定實例進行實例化?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

限時送ChatGPT賬號..

見標題.我有一個模板.我想強制實例化模板的特定實例.我該怎么做?

See title. I have a template. I want to force a particular instance of a template to instantiate. How do I do this?

更具體地說,您能否強制實例化抽象模板類?

More specifically, can you force an abstract template class to instantiate?

我可能會詳細說明,因為我有同樣的問題.在我的例子中,我正在構(gòu)建一個庫,一些模板實現(xiàn)很大并且包含很多東西,但只為幾種類型生成.我想在庫中編譯它們并導(dǎo)出所有方法,但不要在任何地方都包含帶有代碼的頭.

I might elaborate as I have the same question. In my case I am building a library, some of the template implementations are large and include lots of stuff, but are only generated for a couple of types. I want to compile them in the library and export all the methods, but not include the header with the code everywhere.

即:

template<class T>
OS_EXPORT_DECL class MyTmpl
{
    T *item1;
public:
    inline T *simpleGetT() { return(item1); } /* small inline code in here */ } 
    T *doSomeReallyBigMergeStuff(T *b); // note only declaration here
};

// *** implementation source file only seen inside library

template<class T>
MyTmpl<T>::doSomeReallyBigMergeStuff(T *b)
{
    ... a really big method, but don't want to duplicate it, 
        so it is a template ...
}

我當然可以引用庫中的所有方法,這將強制它們編譯和導(dǎo)出,但我不想將不需要的代碼添加到庫中,例如項目的參數(shù)格式和調(diào)用它們的代碼等

I could of course reference all the methods inside the library which would force them to compile and export but the desire isn't to add un-needed code to the library like the argument formatting for the items and the code to call them etc.

?????具體來說,我正在為多個版本的 MSC 和 GCC 以及英特爾編譯器構(gòu)建庫.

????? specifically I am building the library for several versions of MSC and GCC and intel compilers.

推薦答案

不能強制實例化泛型模板,編譯器只能在類型完全已知的情況下生成代碼.

You can't force generic templates to instantiate, the compiler can only generate code if the type is completely known.

通過顯式提供所有類型來強制實例化:

Forcing an instantiation is done by providing all types explicitly:

template class std::vector<int>;

Comeaus 模板常見問題 詳細介紹了相關(guān)問題.

Comeaus template FAQ covers the related issues in some detail.

這篇關(guān)于如何強制 C++ 模板的特定實例進行實例化?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

Difference between std::reference_wrapper and simple pointer?(std::reference_wrapper 和簡單指針的區(qū)別?)
Difference between const. pointer and reference?(常量之間的區(qū)別.指針和引用?)
How to access the contents of a vector from a pointer to the vector in C++?(c++ - 如何從指向向量的指針訪問向量的內(nèi)容?)
Meaning of *amp; and **amp; in C++(*amp; 的含義和**amp;在 C++ 中)
Why can#39;t I do polymorphism with normal variables?(為什么我不能對普通變量進行多態(tài)?)
Dereferencing deleted pointers always result in an Access Violation?(取消引用已刪除的指針總是會導(dǎo)致訪問沖突?)
主站蜘蛛池模板: 一级片免费视频 | 日韩精品 | 天天影视亚洲综合网 | 亚洲成av人片在线观看无码 | 日本天堂视频 | 91香蕉视频在线观看 | www.一区二区三区 | 国产激情在线播放 | 亚洲欧美日韩激情 | 国产高清久久 | 少妇久久久久 | 国产精品视频网 | 一区二区三区电影在线观看 | 欧美不卡一区二区三区 | 日韩精品成人免费观看视频 | 久久久高清 | 中文字幕 在线观看 | 国产视频中文字幕 | 国产性网 | 日本在线播放一区二区 | 国产毛片久久久久久久久春天 | 成人自拍av | 中文字幕亚洲精品 | 精品一区欧美 | 久久精点视频 | 欧美日韩精品亚洲 | 九九久久精品 | 欧美国产日韩在线观看 | 成人欧美一区二区三区黑人孕妇 | 日韩av一区二区在线观看 | 午夜成人在线视频 | 亚洲精品在线免费看 | 午夜久久av | 2021狠狠天天天 | 国产成人精品网站 | 国产午夜精品一区二区三区四区 | 国产99久久精品一区二区永久免费 | 国产日韩一区二区三区 | 日韩免费av | 亚洲天堂网站 | 亚洲电影第三页 |