| |
| Posted by Matthew in reply to Adi Shavit | PermalinkReply |
|
Matthew
Posted in reply to Adi Shavit
| You use conversion constructor and copy assignment, as in:
interface_ptr<IBaseFilter> pSource; // The interface_ptr<> object
{
IBaseFilter* ppSource= NULL; // temporary bare pointer
if(FAILED(pGraph->AddSourceFilter(a2w(c_str_ptr(filename)),0,&ppSource)))
{
//...
return 0;
}
pSource = interface_ptr<IBaseFilter>(ppSource, false); // setting the smart pointer.
}
But since, in your code, you've not used a typedef (I would usually define IBaseFilter_ptr) this looks like more of a burden than I'm used to.
There's no reason why you should do the typedef thing, of course.
btw, I would normally do this differently, as in:
{
IBaseFilter* ppSource= NULL; // temporary bare pointer
if(FAILED(pGraph->AddSourceFilter(a2w(c_str_ptr(filename)),0,&ppSource)))
{
//...
return 0;
}
else
{
interface_ptr<IBaseFilter> pSource(ppSource, false); // setting the smart pointer.
. . .
}
}
But again, there's no reason why you _must_ follow the way I do it. So it looks like a set() method's called for. (As you'll probably have picked up on by now, I don't like adding _any_ functionality until it's proven to be needed. But, once it's proven, well ...)
I'll make this change now, and it'll be in beta 31 (31!). That should be available in the next 36 hrs, maybe sooner. ;-)
Cheers
Matthew
"Adi Shavit" <adish@gentech.co.il> wrote in message news:4575C6FD.9060408@gentech.co.il...
I see that ref_ptr doesn't have a set() method.
How can I implement the code I posted before:
// Create a source filter specified by filename
interface_ptr<IBaseFilter> pSource; // The interface_ptr<> object
{
IBaseFilter* ppSource= NULL; // temporary bare pointer
if(FAILED(pGraph->AddSourceFilter(a2w(c_str_ptr(filename)),0,&ppSource)))
{
//...
return 0;
}
pSource.set(ppSource, false); // setting the smart pointer.
}
Am I missing something??
Adi
Adi Shavit wrote:
I wasn't even aware of ref_ptr.
I'll try it and let you know how it goes.
Adi
Matthew wrote:
Adi
comstl::interface_ptr<> is obsolete. It offers nothing that stlsoft::ref_ptr<> does not; it actually offers less.
I don't know why this component has continued to be available. I've just grepped all my sources and can find only a single use of it (which I've just changed).
My apologies for having left it in there.
The preferred approach is to use stlsoft::ref_ptr<>. Why? Because it facilitates forward declaration of a smart pointer specialisation. (I'm working on a small article to explain how/why, which I hope to publish - perhaps on CodeProject - soonish.)
I'm changing comstl/smartptr/interface_ptr.hpp as we speak to issue a warning if included, and will redefine the class to be implemented in terms of stlsoft::ref_ptr<>.
Sorry about that ... :$
Matthew
And now to the next question ...
|