Hi,
I've made a class whose member is a reference to a dynamically created object. How should I code a destructor?
mmasny
0
Light Poster
Recommended Answers
Jump to PostIf the reference (e.g. int*& thingy;) was actually allocated somewhere else then your class destructor should not do anything with it. Let whatever created it destroy it.
Jump to PostWithout knowing exactly how your class works, it's hard to say.
However, a good rule of thumb:
If you use the "new" keyword in the class' constructor, you will need to use the "delete" keyword in the matching destructor.[edit]
Looks like AD beat me to it.
All 8 Replies
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
Fbody
682
Posting Maven
Featured Poster
mmasny
0
Light Poster
mattjbond
54
Junior Poster
mmasny
0
Light Poster
mattjbond
54
Junior Poster
mmasny
0
Light Poster
mmasny
0
Light Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.