vendredi 23 novembre 2018

Non-Movable C++11 Unique Pointer

I came across this answer Prevent moving of a unique_ptr C++11. However while trying it out on a compiler online, I'm seeing some awkward behavior. Shouldn't the line with the std::move throw an error below?

template <typename T>
using scoped_ptr = const std::unique_ptr<T>;

int main()
{
    auto p = scoped_ptr<int>(new int(5));
    auto p2 = std::move(p); // should be error?
    std::cout << *p2 << std::endl; // 5
    return 0;
}

You can try it online here.

Aucun commentaire:

Enregistrer un commentaire