Deep wrote:
I'm in doubt about what is smart pointer. so, please give me simple
description about smart pointer and an example of that. I'm just
novice in c++.
A smart pointer is basically a type (usually a template type) that
behaves like a pointer but restricts what you can do with a pointer.
Many smart pointers adopt the RAII idiom (google it) and help make you
code exception safe.
There are many different flavours - std::auto_ptr is the only currently
standard one (iirc) and std::shared_ptr is coming soon in the next
revision of the standard which implements a "reference counted" lifetime
management.
There are others - Austria C++ and Loki just to name a couple.
The amount of code in a smart pointer is rather small but the order of
operations implementing a smart pointer can be rather tricky. You need
to deal with things like self assignment and self deletion, thread
safety etc. If you choose to use smart pointers, regular pointers
almost disappear in your code.
Memory leaks usually disappear as well. I've been using smart pointers
now for about 7 years. Only in the last 5 have compilers really been up
to scratch when it comes to supporting them well enough.
Download one of the smart pointer packages and give it a try.