自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

C++標準擴展應(yīng)用技巧分享

開發(fā) 后端
我們今天在這篇文章中主要為大家介紹了C++標準擴展的一些基本應(yīng)用。對C++編程語言有興趣的朋友們可以從中加深對這一語言的認知程度。

對于經(jīng)驗豐富的編程人員來說,C++編程語言他們應(yīng)該再熟悉不過了。這樣一款功能強大的語言,給他們的程序開發(fā)帶來了非常大的好處,我們今天就可以從C++標準擴展的方法來體驗一下這語言的功能特點。

今天實驗一下C++標準擴展中的shared_ptr的使用,結(jié)果在gcc4.1上怎么也編譯不過去,上網(wǎng)查了一下,還下載了TR1的手冊。終于明白了,要在#include中加入

  1. #include < tr1/memory> 
  2. #include < iostream> 
  3. #include < string> 
  4. #include < tr1/array> 
  5. #include < tr1/memory> 
  6. using namespace std;  
  7. using std::tr1::shared_ptr;  
  8.  
  9. class Widget  
  10. {  
  11. public:  
  12. Widget()   
  13. {  
  14. pstr = new string("Hello world!");  
  15. cout < <  "Widget's construction is called" < <  endl;   
  16. }  
  17. Widget(const Widget& rhs) { cout < <  "Widget's copy 
    construction is called" 
    < <  endl; }  
  18. Widget& operator=(const Widget& rhs) { return *this; }  
  19. ~Widget()   
  20. {  
  21. delete pstr;  
  22. cout < <  "Destruction is called" < <  endl;   
  23. }  
  24. private:  
  25. string* pstr;  
  26. };  
  27. int main()  
  28. {  
  29. auto_ptr< Widget> pInv(new Widget);  
  30. auto_ptr< Widget> pInv2(pInv);  
  31. shared_ptr< Widget> pInvN(new Widget);  
  32. array< int, 5> a = {{1,2,3,4,5}};  
  33. cout < <  a[3] < <  endl;  
  34. return 0;  

這個文件。呵呵,可能是自己太不小心了!這次C++標準擴展的部分,根據(jù)TR1的說明主要有:

  1. Reference Wrappers   
  2. Shared_ptr   
  3. result_of   
  4. mem_fn   
  5. Function Object Binders   
  6. Polymorphic Function Wrappers   
  7. Type Traits   
  8. Random Numbers   
  9. Tuples   
  10. Array   
  11. Hash Functions   
  12. Regular Expressions   
  13. Complex Number Algorithms 

這些C++標準擴展部分,我們看到了期待以久的正則表達式也在這里面哦!

【編輯推薦】

  1. C++單件模式實現(xiàn)代碼詳解
  2. C++獲取文件具體方法詳解
  3. C++ makefile寫法標準格式簡介
  4. C++統(tǒng)計對象個數(shù)方法詳解
  5. C++ #define預(yù)處理指令特點評比
責任編輯:曹凱 來源: 博客園
相關(guān)推薦

2010-02-01 11:13:00

C++ Traits

2010-02-04 14:58:06

C++內(nèi)存分配

2010-02-01 17:09:07

C++鏈表操作

2010-02-05 13:44:06

C++ eof()函數(shù)

2010-02-06 14:28:38

C++標準輸入輸出

2010-02-06 16:16:01

C++冒泡排序

2010-02-05 18:04:21

C++剪切板

2011-07-13 16:36:11

C++

2010-02-03 15:35:00

C++輸入輸出漢字

2010-02-05 17:25:26

C++標識符命名規(guī)則

2010-02-26 10:46:12

WCF行為擴展

2010-02-06 13:52:39

C++ profile

2010-02-06 10:24:48

C++二維數(shù)組初始化

2010-02-06 17:09:29

C++文件拷貝

2010-02-04 11:38:43

C++獲取當前路徑

2010-02-02 10:46:51

C++獲取文件大小

2009-12-08 13:18:17

2010-02-03 16:04:34

C++標準類庫

2010-02-04 15:19:38

C++獲取CPU信息

2010-02-06 17:21:20

C++ CreateT
點贊
收藏

51CTO技術(shù)棧公眾號