vendredi 26 mars 2021

Why does push_back fail for unique_ptr of string vectors?

The code below has a segmentation fault. When there is not a unique_ptr involved everything works fine.

int main() {
  auto vect = std::unique_ptr<std::vector<std::string>>();
  vect->push_back("abc");  // Segmentation Fault.
  vect->emplace_back("abc");  // Segmentation Fault.
  return 0;
}

In case this matters, I'm compiling using g++ 10.2 on Ubunutu.

Aucun commentaire:

Enregistrer un commentaire