久久久久久久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?(取消引用已刪除的指針總是會導致訪問沖突?)
主站蜘蛛池模板: 国产99久久久国产精品下药 | 人人亚洲| caoporn国产| 欧洲精品在线观看 | 一级黄色片日本 | 91在线免费视频 | 天天干天天插天天 | 老司机免费视频 | 99精品久久 | 日韩中文字幕视频 | 不卡一区二区三区四区 | 亚洲精品国产第一综合99久久 | 波霸ol一区二区 | 国产电影一区二区 | 欧美日韩在线视频观看 | 99精品免费久久久久久久久日本 | 一区二区三区回区在观看免费视频 | www312aⅴ欧美在线看 | 国产高清视频在线播放 | 正在播放国产精品 | 久久在线 | 成人毛片在线视频 | 亚洲黄色高清视频 | 久久精品综合 | 国产欧美性成人精品午夜 | 亚洲aⅴ| 婷婷午夜天 | 欧美韩一区二区三区 | 色在线免费视频 | 日韩在线 | 亚洲国产福利视频 | 精品日韩一区二区 | 午夜影院网站 | 波多野吉衣久久 | 亚洲精品欧美一区二区三区 | 久久精品免费 | 国产成人网| 特级做a爰片毛片免费看108 | 亚洲欧美在线观看视频 | 欧美最猛性xxxxx亚洲精品 | 欧美日本韩国一区二区 |