本文介紹了= 函數聲明后刪除的含義的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
class my_class
{
...
my_class(my_class const &) = delete;
...
};
= delete
在這種情況下是什么意思?
What does = delete
mean in that context?
是否還有其他修飾符"(除了= 0
和= delete
)?
Are there any other "modifiers" (other than = 0
and = delete
)?
推薦答案
刪除函數是一種 C++11個特點:
現在可以表達禁止復制"的常見成語直接:
The common idiom of "prohibiting copying" can now be expressed directly:
class X {
// ...
X& operator=(const X&) = delete; // Disallow copying
X(const X&) = delete;
};
[...]
刪除"機制可用于任何功能.例如,我們可以消除這樣的不需要的轉換:
The "delete" mechanism can be used for any function. For example, we can eliminate an undesired conversion like this:
struct Z {
// ...
Z(long long); // can initialize with an long long
Z(long) = delete; // but not anything less
};
這篇關于= 函數聲明后刪除的含義的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!