is this is the correct way 2 write destructor of copy constructor and parameterised constructor
~a(int x,float y)
~a(a &a1)

Recommended Answers

All 4 Replies

No there is only ever a single destructor

~a()
{
}

It never takes any parameters. This makes sense, the reason that you have parameterised constructors is that you may wish to initialise your object in several different ways, but when you destroy your object there is no need for any further data, you go from the current state of the object to no-object so the object already knows everything it needs in order to delete itself.

it means there will be only one destructor in class to destroy all the objects.......

Yes, that's how it's supposd to work :)

Why would you not want to do that? When you destroy an object, it's not supposed to be used anymore.

it means there will be only one destructor in class to destroy all the objects.......

I would like to point out that a destructor if called by an object destroys that particular instance of object. Each object should call the destructor separately to remove their corresponding instances.

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.