473,396 Members | 2,029 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

Jul 23 '05 #1
0 1007

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: David B. Held | last post by:
I wanted to post this proposal on c.l.c++.m, but my news server apparently does not support that group any more. I propose a new class of exception safety known as the "smart guarantee". ...
1
by: Shiva | last post by:
I saw C++ FAQ LITE on how to go about creating a smart pointer. I tried my hand at creating a smart pointer using templates. I'm thinking of creating just one Pointer class to create pointers for...
8
by: Axter | last post by:
I normally use a program call Doxygen to document my source code.(http://www.stack.nl/~dimitri/doxygen) This method works great for small and medium size projects, and you can get good...
6
by: zl2k | last post by:
hi, When I considered about preventing memory leaking, the method came up to my mind is using boost smart pointer if possible (use stl::vector instead of type, use smart pointer whenever declare...
92
by: Jim Langston | last post by:
Someone made the statement in a newsgroup that most C++ programmers use smart pointers. His actual phrase was "most of us" but I really don't think that most C++ programmers use smart pointers,...
33
by: Ney André de Mello Zunino | last post by:
Hello. I have written a simple reference-counting smart pointer class template called RefCountPtr<T>. It works in conjunction with another class, ReferenceCountable, which is responsible for the...
11
by: Nindi73 | last post by:
A few days a ago I posted my code for a deep copy pointer which doesn't require the pointee object to have a virtual copy constructor. I need help with checking that it was exception safe and...
54
by: Boris | last post by:
I had a 3 hours meeting today with some fellow programmers that are partly not convinced about using smart pointers in C++. Their main concern is a possible performance impact. I've been explaining...
50
by: Juha Nieminen | last post by:
I asked a long time ago in this group how to make a smart pointer which works with incomplete types. I got this answer (only relevant parts included): ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.