[Scummvm-devel] SharedPtr usage

Max Horn max at quendi.de
Tue Apr 1 10:40:13 CEST 2008


Am Di, 1.04.2008, 09:34, schrieb Peres:
> Hi there
>
> I could finally try SharedPtr (revision 31287). Latest revision (31346) is
> now on my computer and will try it later if I get time, so what I write
> may be outdated/wrong. On the other side, I can't foresee when I will be
> able to connect again, so please be patient.
>
> There is a routine in Parallaction (findZone) that scans two lists, one
> containing SharedPtr<A>'s and one containing SharedPtr<B>'s (with B
> subclassing A). The routine should be able to return a SharedPtr<A> if a
> certain condition is matched, or NULL (or similar) if no match is found.
>
> The comments in common/ptr.h (at lines 98-99) suggest assigning a
> SharedPtr<B> to a SharedPtr<A> when B subclasses A is possible, but I
> haven't been able to do so (I tried!).

That should work, at least with latest SVN it does. See also the test case
in  test/common/ptr.h in function test_case (at the very end).

>
> Also, how do you simulate a NULL value with SharedPtr<A>? Is a
> SharedPtr<A> that has been initialised by its default constructor a NULL
> SharedPtr<A>?

Yes, that should work.

>
> Both the issues above can be dealt with by resorting to the get() method
> and working with raw pointers, but that probably defeats the whole
> SharedPtr concept. Somebody please give some wisdom here :)
>

Indeed, don't use get() like that -- or if you do, be sure you know what
you do (in particular, do not store that derived pointer!)

Bye,
Max




More information about the Scummvm-devel mailing list