Bibliothèque d'exceptions C ++ - bad_weak_ptr

La description

C'est un mauvais pointeur faible.

Déclaration

Voici la déclaration pour std :: bad_weak_ptr.

class bad_weak_ptr: public exception;

C ++ 11

class bad_weak_ptr: public exception;

Paramètres

aucun

Valeur de retour

aucun

Des exceptions

No-throw guarantee - aucun membre ne lance d'exceptions.

Exemple

Dans l'exemple ci-dessous pour std :: bad_typeid.

#include <memory>
#include <iostream>
int main() {
   std::shared_ptr<int> p1(new int(42));
   std::weak_ptr<int> wp(p1);
   p1.reset();
   try {
      std::shared_ptr<int> p2(wp);
   } catch(const std::bad_weak_ptr& e) {
      std::cout << e.what() << '\n';
   }
}

L'exemple de sortie devrait être comme ceci -

bad_weak_ptr