Topic: Template for Smart Pointer (was proposal: PROPOSAL: template ...)
Author: shang@corp.mot.com (David L. Shang)
Date: Tue, 29 Mar 1994 23:59:03 GMT Raw View
In article <2n82pi$fhi@mailhost.interaccess.com> bobzim@interaccess.com (Bob
Zimmerman) writes:
> Dave Jones (djones@megatest.com) wrote:
> : Here's the problem that prompted this proposal: I want to abstract the
> : notion of a pointer, so that I can write templates that can use
> : "smart pointers" of various types.
>
> : As it stands, class-arguments to templates must be fully qualified types,
> : not parameterized types.
Correct. Only languages like Cluster that supports dynamic genericity can fully
support what you need:
smart obj: BaseClass;
...
obj := new DerivedClass; /* a smart pointer is created */
obj.foo(...); /* foo in DerivedClass is called */
where "smart" is a *user-defined* parameterized class:
class smart [ T < anyclass ] begin ... end;
and declaration:
smart obj: BaseClass;
is a sytax sugar for:
var obj: smart [ T < BaseClass ];
You can also have your persistent object reference like:
persistent obj: BaseClass;
as long as you define a "persistent" class.
Other examples are remote object, atomic object, etc.
>
> I have to go back to some code I have, but I believe that as long as you
> have completed defined and implemented (e.g. in another .hpp and .cpp)
> file the template PTR (in your example), you should be able to do exactly
> what you are doing...
>
C++ template, no matter how many nested level presented in args, is by nature a
STATIC expansion language feature. It can do NOTHING with DYNAMIC binding,
which is the basic requirement for any POINTER protocol.
David Shang