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

基于其返回類型的函數模板推導?

Template deduction for function based on its return type?(基于其返回類型的函數模板推導?)
本文介紹了基于其返回類型的函數模板推導?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我希望能夠使用模板推導來實現以下目標:

I'd like to be able to use template deduction to achieve the following:

GCPtr<A> ptr1 = GC::Allocate();
GCPtr<B> ptr2 = GC::Allocate();

而不是(我目前擁有的):

instead of (what I currently have):

GCPtr<A> ptr1 = GC::Allocate<A>();
GCPtr<B> ptr2 = GC::Allocate<B>();

我當前的 Allocate 函數如下所示:

My current Allocate function looks like this:

class GC
{
public:
    template <typename T>
    static GCPtr<T> Allocate();
};

這能去掉額外的嗎?

推薦答案

那是不可能的.返回類型不參與類型推導,而是已經匹配了適當的模板簽名的結果.不過,您可以將其隱藏在大多數用途中:

That cannot be done. The return type does not take part in type deduction, it is rather a result of having already matched the appropriate template signature. You can, nevertheless, hide it from most uses as:

// helper
template <typename T>
void Allocate( GCPtr<T>& p ) {
   p = GC::Allocate<T>();
}

int main()
{
   GCPtr<A> p = 0;
   Allocate(p);
}

該語法實際上比最初的 GCPtr 好還是差?p = GC::Allocate() 是另一個問題.

Whether that syntax is actually any better or worse than the initial GCPtr<A> p = GC::Allocate<A>() is another question.

附言c++11 將允許您跳過類型聲明之一:

P.S. c++11 will allow you to skip one of the type declarations:

auto p = GC::Allocate<A>();   // p is of type GCPtr<A>

這篇關于基于其返回類型的函數模板推導?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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?(取消引用已刪除的指針總是會導致訪問沖突?)
主站蜘蛛池模板: 久久视频一区 | 少妇一级淫片免费看 | 神马福利视频 | 精品久久免费视频 | 国产精品欧美精品 | 国产在线高清 | 一区二区三区精品 | 国产91av在线 | 国产精品久久久久久久久借妻 | 久久超 | 丰满少妇高潮在线观看 | 欧美日韩毛片 | 中文字幕一区二区在线播放 | 亚洲黄色在线视频 | 亚洲丝袜av | 日本中文字幕在线播放 | 看黄网址 | 色综合久久88色综合天天 | 蜜臀久久99精品久久久久久宅男 | 欧美国产在线视频 | 欧美日韩国产在线观看 | 亚洲精品中文字幕乱码三区91 | 久久亚洲成人 | 欧美精品网站 | 亚洲视频在线免费观看 | 在线观看日本 | 色片在线观看 | 日韩国产一区二区 | 国产综合久久久 | 新av在线 | av在线播放网址 | 日日干夜夜草 | 欧美a在线观看 | 亚洲久久久| 伊人久久国产 | 黄色录像免费观看 | 国产精品理论 | 国产不卡在线 | 欧美一级艳片视频免费观看 | 羞羞在线视频 | 黄色片免费看 |