新聞中心
這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
C++標(biāo)準(zhǔn)擴(kuò)展應(yīng)用技巧分享
對(duì)于經(jīng)驗(yàn)豐富的編程人員來(lái)說(shuō),C++編程語(yǔ)言他們應(yīng)該再熟悉不過(guò)了。這樣一款功能強(qiáng)大的語(yǔ)言,給他們的程序開(kāi)發(fā)帶來(lái)了非常大的好處,我們今天就可以從C++標(biāo)準(zhǔn)擴(kuò)展的方法來(lái)體驗(yàn)一下這語(yǔ)言的功能特點(diǎn)。

今天實(shí)驗(yàn)一下C++標(biāo)準(zhǔn)擴(kuò)展中的shared_ptr的使用,結(jié)果在gcc4.1上怎么也編譯不過(guò)去,上網(wǎng)查了一下,還下載了TR1的手冊(cè)。終于明白了,要在#include中加入
- #include < tr1/memory>
- #include < iostream>
- #include < string>
- #include < tr1/array>
- #include < tr1/memory>
- using namespace std;
- using std::tr1::shared_ptr;
- class Widget
- {
- public:
- Widget()
- {
- pstr = new string("Hello world!");
- cout < < "Widget's construction is called" < < endl;
- }
- Widget(const Widget& rhs) { cout < < "Widget's copy
construction is called" < < endl; }- Widget& operator=(const Widget& rhs) { return *this; }
- ~Widget()
- {
- delete pstr;
- cout < < "Destruction is called" < < endl;
- }
- private:
- string* pstr;
- };
- int main()
- {
- auto_ptr< Widget> pInv(new Widget);
- auto_ptr< Widget> pInv2(pInv);
- shared_ptr< Widget> pInvN(new Widget);
- array< int, 5> a = {{1,2,3,4,5}};
- cout < < a[3] < < endl;
- return 0;
- }
這個(gè)文件。呵呵,可能是自己太不小心了!這次C++標(biāo)準(zhǔn)擴(kuò)展的部分,根據(jù)TR1的說(shuō)明主要有:
- Reference Wrappers
- Shared_ptr
- result_of
- mem_fn
- Function Object Binders
- Polymorphic Function Wrappers
- Type Traits
- Random Numbers
- Tuples
- Array
- Hash Functions
- Regular Expressions
- Complex Number Algorithms
這些C++標(biāo)準(zhǔn)擴(kuò)展部分,我們看到了期待以久的正則表達(dá)式也在這里面哦!
標(biāo)題名稱:C++標(biāo)準(zhǔn)擴(kuò)展應(yīng)用技巧分享
本文URL:http://m.fisionsoft.com.cn/article/dhjpgis.html


咨詢
建站咨詢
