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

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

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

問題描述

限時送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?

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

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 ...
}

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

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 以及英特爾編譯器構建庫.

????? 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 模板常見問題 詳細介紹了相關問題.

Comeaus template FAQ covers the related issues in some detail.

這篇關于如何強制 C++ 模板的特定實例進行實例化?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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?(取消引用已刪除的指針總是會導致訪問沖突?)
主站蜘蛛池模板: 国产在线色 | 一二区成人影院电影网 | 久久9视频 | 欧美精品一二三 | 欧美日韩一区二区在线观看 | 性高湖久久久久久久久3小时 | 一区二区三区观看视频 | 深夜福利影院 | 好姑娘高清在线观看电影 | 成人在线精品视频 | 国产成人在线免费 | 九色网址 | 国产成人免费视频网站高清观看视频 | 久久精品免费观看 | 国产露脸对白88av | 亚洲午夜精品视频 | 亚洲黄色av网站 | av中文字幕在线 | 青青久久av北条麻妃海外网 | 日韩成人免费 | 91精品在线播放 | 亚洲在线看 | 在线男人天堂 | 精品一区二区久久久久久久网站 | 涩涩视频在线观看 | 日本福利一区 | 国产精品一区二区在线播放 | 一区二区免费视频 | 国产伦一区二区三区视频 | 久久久久亚洲 | 久久久黄色 | 亚洲精品一区二区三区蜜桃久 | 日韩精品在线免费观看视频 | 婷婷在线视频 | 国产精品久久久一区二区三区 | 久热9 | 国产精品久久久久久久久久久久久久 | 国产综合久久 | 久久久www | 久久久久久国产精品 | 国产精品精品 |