Reply to post: Re: not-so-smart with pointers

Carnegie-Mellon Uni emits 'don't be stupid' list for C++ developers

sed gawk

Re: not-so-smart with pointers

Smart pointers are about communicating something to the reader.

std::unique_ptr<Foo> foo ; // I own this, I can move ownership but I cant (share/copy), lifetime is as mine.

std::shared_ptr<Foo> foo; // I have an interest in this, it might outlive me, but my share keeps it alive.

std::weak_ptr<Foo> foo; // I have an interest in this, but my interest doesn't keep it alive.

Foo * foo; // a wild pointer, set to whatever what on the stack last.

POST COMMENT House rules

Not a member of The Register? Create a new account here.

  • Enter your comment

  • Add an icon

Anonymous cowards cannot choose their icon

Biting the hand that feeds IT © 1998–2019