Smart Pointers

General

Prefer unique_ptr by default. If you do know from the start you need shared ownership, however, go directly to shared_ptr via make_shared.
With unique_ptr , you can still put it in a container (e.g., vector<unique_ptr<widget>>) and do most other things you want to do with a raw pointer, only safely.
Whenever possible, use the make_shared function to create a shared_ptr when the memory resource is created for the first time.

For general use, take T* or T& arguments rather than smart pointers
Smart pointer rule summary

Unique pointer as class member

class A {
private:
   std::unique_ptr<MyType> mt;
public:
   void initStuff() {
      mt = StaticFuncSomewhereElese::generateMyType();
   }
};
 
std::unique_ptr<MyType> StaticFuncSomewhereElese::generateMyType() {
    auto temp = std::make_unique<MyType>(…);
    // `make_unique` is C++14 (although trivially implementable in C++11).
    // Here's an alternative without `make_unique`:
    // std::unique_ptr<MyType> temp(new MyType(…));
 
    //do stuff to temp (read file or something...)
    return temp;
}

Unique pointer in containers

std::unique_ptr<test1> us(new test1());
std::vector<std::unique_ptr<test1>> vec;

vec.push_back(move(us));
// or
vec.push_back(std::unique_ptr<test1>(new test1()));
// or
vec.push_back(std::make_unique<test1>()); // make_unique requires C++1

// FAIL: for (auto i: AVLTree) { ... } - tries to make a copy of each element.
for (auto& i: AVLTree) { ... }
for (auto const& i: AVLTree) { ... }

Links