T
Tony Johansson
Hello Experts!
I reading a book called programming with design pattern revealed
by Tomasz Muldner and here I read something that I don't understand so I ask
you.
First some background below is a class ResourceHandle that is a wrapper
class.
The copy constructor and the assignment operator are private to disallow
copying of the ResourcePointer
handle. The constructor associates the handle with the pointer to Resource
and the destructor deletes this pointer. Here I can use ResourceHandle
anywhere I can use ResourcePointer.
There is also a type conversion from ResourceHandle to ResourcePointer.
Now to my question what kind of expression is this
ResourceHandle r(newResource());
What I have found it's the same as I think.
Resource* r(new Resource());
But I'm not familar with that expression either.
Is this Resource* r(new Resource()); the same as
Resource* r = new Resource();
typedef Resource* ResourcePointer;
class ResourceHandle
{
public:
ResourceHandle(const ResourcePointer& r) : handle(r) {}
virtual ~ResourceHandle()
{ delete handle; }
operator ResourcePointer() const //type conversion from ResourceHandle
to ResourcePointer
{ return handle; }
private:
ResourcePointer handle;
ResourceHandle(const ResourceHandle&);
ResourceHandle% operator=(const ResourceHandle&);
};
Many thanks
//Tony
I reading a book called programming with design pattern revealed
by Tomasz Muldner and here I read something that I don't understand so I ask
you.
First some background below is a class ResourceHandle that is a wrapper
class.
The copy constructor and the assignment operator are private to disallow
copying of the ResourcePointer
handle. The constructor associates the handle with the pointer to Resource
and the destructor deletes this pointer. Here I can use ResourceHandle
anywhere I can use ResourcePointer.
There is also a type conversion from ResourceHandle to ResourcePointer.
Now to my question what kind of expression is this
ResourceHandle r(newResource());
What I have found it's the same as I think.
Resource* r(new Resource());
But I'm not familar with that expression either.
Is this Resource* r(new Resource()); the same as
Resource* r = new Resource();
typedef Resource* ResourcePointer;
class ResourceHandle
{
public:
ResourceHandle(const ResourcePointer& r) : handle(r) {}
virtual ~ResourceHandle()
{ delete handle; }
operator ResourcePointer() const //type conversion from ResourceHandle
to ResourcePointer
{ return handle; }
private:
ResourcePointer handle;
ResourceHandle(const ResourceHandle&);
ResourceHandle% operator=(const ResourceHandle&);
};
Many thanks
//Tony