lundi 28 décembre 2020

why am I getting free(): invalid pointer error after program ends

Can somebody explain why I'm getting this error after program ends?

free(): invalid pointer

This is my code:

#include <iostream>
#include <memory>

int main()
{
    int a = 3;
    std::unique_ptr<int> up(&a);
    
    std::cout << a << std::endl;
    std::cout << *up << std::endl;
    
    std::cout << &a << std::endl;
    std::cout << up.get() << std::endl;
    
    return 0;
}

Aucun commentaire:

Enregistrer un commentaire