对于经验丰富的编程人员来说,C++编程语言他们应该再熟悉不过了。这样一款功能强大的语言,给他们的程序开发带来了非常大的好处,我们今天就可以从C++标准扩展的方法来体验一下这语言的功能特点。
今天实验一下C++标准扩展中的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< int, 5> a = {{1,2,3,4,5}};
cout < < a[3] < < endl;
return 0;
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
这个文件。呵呵,可能是自己太不小心了!这次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
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
这些C++标准扩展部分,我们看到了期待以久的正则表达式也在这里面哦!
【编辑推荐】