lothar.behrens@lollisoft. Guest
|
Posted: Fri Apr 29, 2005 1:10 pm Post subject: Smart pointer without templates possible ? |
|
|
Hi,
a long time ago I had implemented my version - or attempt - of a smart
pointer.
It is not well and most books I have read afterwards are using
templates :-(
It is macro based and now I must see, that there are some ugly code
constructs,
that I like to avoid in future.
This is the macro (not complete):
#define UAP(interface, Unknown_Reference)
class UAP##Unknown_Reference {
public:
UAP##Unknown_Reference();
UAP##Unknown_Reference(const UAP##Unknown_Reference& _ref);
void operator=(const UAP##Unknown_Reference& _ref);
interface* LB_STDCALL operator -> () const;
interface* LB_STDCALL operator -> ();
interface* LB_STDCALL operator == (const interface* b);
interface* LB_STDCALL operator != (const interface* b);
}
The problem is, if I use it for two pointers of same type, I cannot
compare
it like this:
UAP(lb_I_String, s1)
UAP(lb_I_String, s2)
// Some code to initialize s1 and s2
if (s1 == s2)
printf("Equal.n");
else
printf("Not equal.n");
I thought, if I use the interface as like this 'UAP##interface' instead
of
'UAP##Unknown_Reference', I will get trouble in double class
definitions.
Would it be possible to solve this by deriving from a base 'UAPBase'
having
the implementations for operator ==, !=, < and so on ?
The implementation of the base, then calls functions like equal...
Thanks
Lothar
|
|