本文介紹了= 函數(shù)聲明后刪除的含義的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!
問(wèn)題描述
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
)?
推薦答案
刪除函數(shù)是一種 C++11個(gè)特點(diǎn):
現(xiàn)在可以表達(dá)禁止復(fù)制"的常見(jiàn)成語(yǔ)直接:
The common idiom of "prohibiting copying" can now be expressed directly:
class X {
// ...
X& operator=(const X&) = delete; // Disallow copying
X(const X&) = delete;
};
[...]
刪除"機(jī)制可用于任何功能.例如,我們可以消除這樣的不需要的轉(zhuǎn)換:
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
};
這篇關(guān)于= 函數(shù)聲明后刪除的含義的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!