STL class for reference-counted pointers?

前端 未结 5 2025
花落未央
花落未央 2021-02-13 23:23

This should be trivial but I can\'t seem to find it (unless no such class exists!)

What\'s the STL class (or set of classes) for smart pointers?

UPDATE

5条回答
  •  醉梦人生
    2021-02-14 00:03

    If you don't want/can't use Boost and your compiler implements TR1, you can use shared_ptr (borrowed from Boost):

    #include 
    
    ...
    
    std::tr1::shared_ptr ptr(new Foo);
    

    Otherwise, no, there are no smart pointers except std::auto_ptr in vanilla STL.

提交回复
热议问题