The fifth edition of c++ primer describes weak_ptr like this:
A weak_ptr is a smart pointer that does not control the lifetime of the object to which it points.Instead,a weak_ptr points to an object that is managed by a shared_ptr.
But why dot operators are used instead of -> when operations such as reset, use_count, and lock are called?
For example:
weak_ptr<int> w(sp);
w.use_count();
w.lock();
>Solution :
std::weak_ptr is a class type, and like any class the . operator is used to access its members via a non-pointer instance of that class.
However, unlike other smart pointer classes, std::weak_ptr does not have an operator-> (or operator*) defined to access the object it refers to. You have to first lock() it to gain access to its associated std::share_ptr, which has those operators defined to access the referred object.