Smart pointer without templates possible ?

L

lothar.behrens

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top