c++标准扩展TR1

今天实验一下TR1的shared_ptr的使用,结果在gcc4.1上怎么也编译不过去,上网查了一下,还下载了TR1的手册。终于明白了,要在#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
<int5> a = {{1,2,3,4,5}};
    cout 
<< a[3<< endl;
    
return 0;
}


这个文件。呵呵,可能是自己太不小心了!
这次C++要扩展的部分,根据TR1的说明主要有:

  • 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

这些部分,我们看到了期待以久的正则表达式也在这里面哦!

posted @ 2008-05-26 11:52  moonz-wu  阅读(2427)  评论(1编辑  收藏  举报