C ++ standard Extended Application Skills

Source: Internet
Author: User

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.

 
 
  1. #include < tr1/memory> 
  2. #include < iostream> 
  3. #include < string> 
  4. #include < tr1/array> 
  5. #include < tr1/memory> 
  6. using namespace std;  
  7. using std::tr1::shared_ptr;  
  8.  
  9. class Widget  
  10. {  
  11. public:  
  12. Widget()   
  13. {  
  14. pstr = new string("Hello world!");  
  15. cout < <  "Widget's construction is called" < <  endl;   
  16. }  
  17. Widget(const Widget& rhs) { cout < <  "Widget's copy 
    construction is called" < <  endl; }  
  18. Widget& operator=(const Widget& rhs) { return *this; }  
  19. ~Widget()   
  20. {  
  21. delete pstr;  
  22. cout < <  "Destruction is called" < <  endl;   
  23. }  
  24. private:  
  25. string* pstr;  
  26. };  
  27. int main()  
  28. {  
  29. auto_ptr< Widget> pInv(new Widget);  
  30. auto_ptr< Widget> pInv2(pInv);  
  31. shared_ptr< Widget> pInvN(new Widget);  
  32. array< int, 5> a = {{1,2,3,4,5}};  
  33. cout < <  a[3] < <  endl;  
  34. return 0;  

This file. Oh, maybe you are too careless! The C ++ standard expansion section mainly includes:

 
 
  1. Reference Wrappers   
  2. Shared_ptr   
  3. result_of   
  4. mem_fn   
  5. Function Object Binders   
  6. Polymorphic Function Wrappers   
  7. Type Traits   
  8. Random Numbers   
  9. Tuples   
  10. Array   
  11. Hash Functions   
  12. Regular Expressions   
  13. Complex Number Algorithms 

We have seen the long-awaited regular expressions in the C ++ standard extensions!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.