boost學習筆記之noncopyable

2021-08-07 05:18:07 字數 415 閱讀 8758

先來看乙個例子:

#include using namespace std;

class test{

public:

test(){cout<<"test()"《如果在類中沒有顯式地宣告乙個拷貝建構函式,那麼,編譯器將會自動生成乙個預設的拷貝建構函式,該建構函式完成物件之間的位拷貝,位拷貝又稱淺拷貝。也就是說預設的c++類是允許複製的。那麼如何實現乙個不能拷貝的類呢?只需要將上面**的注釋開啟。用protected或者private修飾重寫的拷貝建構函式即可。這時候test p(t);test p1 = t;2個語句就會報錯

boost中noncopyable實現的原理就是如此。故我們使用boost實現乙個不可拷貝的類的時候只需要繼承noncopyable類即可。使用noncopyable需要包含標頭檔案

#include

Boost學習筆記之type traits(一)

筆記 實現 僅摘取一部分 理解原理 不是完整的boost 依賴的標頭檔案 include or include 實現原理 template struct add const template struct add const add const type int const add const ty...

boost 學習筆記

先來看看如何賦值把 include include include include include include include using namespace std int tmain int argc,tchar ar include include include include incl...

Boost學習筆記 operators

如果乙個類要實現operator operator 意味著可能也要實現operator operator 等其它操作符。只要提供了operator operator 就可以根據這兩個操作符實現operator operator 等其它操作符。而且這種實現是單調的 operator const t x...