For experienced programmers, the C ++ programming language should be more familiar. Such a powerful language brings great benefits to their program development, today, we can use the C ++ standard extension method to experience the features of this language.
Today, I tried to use shared_ptr in the C ++ standard extension. I couldn't compile it on gcc4.1. I checked it online and downloaded the TR1 manual. Finally, I understand that I want to add it to # 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;
- }
This file. Oh, maybe you are too careless! The C ++ standard expansion section mainly includes:
- 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
We have seen the long-awaited regular expressions in the C ++ standard extensions!