c++标准扩展TR1

今天实验一下TR1的shared_ptr的使用,结果在gcc4.1上怎么也编译不过去,上网查了一下,还下载了TR1的手册。终于明白了,要在#include中加入
#include <tr1/memory>

None.gif#include <iostream>
None.gif#include 
<string>
None.gif#include 
<tr1/array>
None.gif#include 
<tr1/memory>
None.gif
using namespace std;
None.gif
using std::tr1::shared_ptr;
None.gif
None.gif
class Widget
ExpandedBlockStart.gifContractedBlock.gif
dot.gif{
InBlock.gif
public:
InBlock.gif    Widget() 
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        pstr 
= new string("Hello world!");
InBlock.gif        cout 
<< "Widget's construction is called" << endl; 
ExpandedSubBlockEnd.gif    }

ExpandedSubBlockStart.gifContractedSubBlock.gif    Widget(
const Widget& rhs) dot.gif{ cout << "Widget's copy construction is called" << endl; }
ExpandedSubBlockStart.gifContractedSubBlock.gif    Widget
& operator=(const Widget& rhs) dot.gifreturn *this; }
InBlock.gif    
~Widget() 
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        delete pstr;
InBlock.gif        cout 
<< "Destruction is called" << endl; 
ExpandedSubBlockEnd.gif    }

InBlock.gif
InBlock.gif
private:
InBlock.gif    
string* pstr;
ExpandedBlockEnd.gif}
;
None.gif
None.gif
None.gif
int main()
ExpandedBlockStart.gifContractedBlock.gif
dot.gif{
InBlock.gif    auto_ptr
<Widget> pInv(new Widget);
InBlock.gif    auto_ptr
<Widget> pInv2(pInv);
InBlock.gif    
InBlock.gif    shared_ptr
<Widget> pInvN(new Widget);
ExpandedSubBlockStart.gifContractedSubBlock.gif    array
<int5> a = dot.gif{dot.gif{1,2,3,4,5}};
InBlock.gif    cout 
<< a[3<< endl;
InBlock.gif    
return 0;
ExpandedBlockEnd.gif}

None.gif


这个文件。呵呵,可能是自己太不小心了!
这次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

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值