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

在 C++0x 中轉發所有構造函數

Forwarding all constructors in C++0x(在 C++0x 中轉發所有構造函數)
本文介紹了在 C++0x 中轉發所有構造函數的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

在 C++0x 中轉發所有父級構造函數的正確方法是什么?

What is the correct way to forward all of the parent's constructors in C++0x?

我一直在這樣做:

class X: public Super {
    template<typename... Args>
        X(Args&&... args): Super(args...) {}
};

推薦答案

C++0x 中有一個更好的方法來解決這個問題

There is a better way in C++0x for this

class X: public Super {
  using Super::Super;
};

如果你聲明一個完美轉發模板,你的類型在重載解析中會表現得很糟糕.假設您的基類可以從 int 轉換,并且有兩個函數可以打印出類

If you declare a perfect-forwarding template, your type will behave badly in overload resolution. Imagine your base class is convertible from int and there exist two functions to print out classes

class Base {
public:
  Base(int n);
};

class Specific: public Base {
public:
  template<typename... Args>
    Specific(Args&&... args);
};

void printOut(Specific const& b);
void printOut(std::string const& s);

你用

printOut("hello");

會叫什么?這是模棱兩可的,因為 Specific 可以轉換任何參數,包括字符數組.它這樣做不考慮現有的基類構造函數.使用 using 聲明繼承構造函數僅聲明使此工作所需的構造函數.

What will be called? It's ambiguous, because Specific can convert any argument, including character arrays. It does so without regard of existing base class constructors. Inheriting constructors with using declarations only declare the constructors that are needed to make this work.

這篇關于在 C++0x 中轉發所有構造函數的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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?(取消引用已刪除的指針總是會導致訪問沖突?)
主站蜘蛛池模板: 欧美一区二区大片 | 成人精品网 | a黄视频| 精品国产精品一区二区夜夜嗨 | 国产精品永久免费观看 | 亚洲一区视频在线 | 日韩在线播放网址 | 亚洲va在线va天堂va狼色在线 | 亚洲天堂久久 | 免费a网 | 9久久婷婷国产综合精品性色 | 日韩精品一区二区在线 | 一区二区三区在线 | 成人av网站在线观看 | 三级黄色片在线播放 | 日本天天操 | 午夜大片 | 中文字幕亚洲欧美日韩在线不卡 | 国产99精品 | 日本免费在线观看视频 | 亚洲最大av | 久久99精品久久久久久琪琪 | 亚洲国产成人精品久久久国产成人一区 | 久久九精品 | 欧美成人第一页 | 亚洲视频一区 | 国产激情一区二区三区 | 精品成人佐山爱一区二区 | 99精品久久久| 欧美日韩专区 | 天堂网avav| 国产精品免费一区二区三区 | 久久这里只有 | 欧美专区在线 | 日韩一级欧美一级 | 欧美日韩电影在线 | 成人一区二区三区在线观看 | 精品国产乱码久久久久久闺蜜 | 久久免费视频在线 | 欧美视频三区 | 日韩精品极品视频在线观看免费 |