const objects calling destructor

hi,
    i have come across a strange problem, causing conflict in concepts.

    It is known that a const object can only call const functions with the exception of constructors and destructors which are called only once and automatically. But i experienced that we can also call the destructor explicitly (c++) :?, but that violates the const object concept as we can call destuctor with it and can do any thing in the function.

   On net the only reason i found for allowing explicit destructor call is to clear the memory, but we can write some memory clean function, as we do initialization functions corresponding to initialization constuctors !!! i am not satisfied with this argument.

  so my question is why explicit call of destructor is allowed? and how is justifies the const obj concept?

  hope i can get some better reasoning from here. really looking forward for replies.

regards
fa
fatimaoAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rajeev_devinCommented:
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
efnCommented:
As the links provided by rajeev_devin explain, the explicit destructor call is allowed as the counterpart of placement new, to make it possible to destroy an object without necessarily releasing its storage.  It's true that one could write a different function to do this, but then if the object were to be used without placement new, there would be two functions that do the same thing, which would be undesirable.  Since the concept of a destructor function that destroys an object was already defined, it was logically consistent to use the same function to do the same job in the placement new case.

The designers of the language had two choices about attempts to call the destructor of a constant object:  they could allow it or not.  If they didn't allow it, all constant objects could never be destroyed and would hang around indefinitely.  If they did allow it, a sufficiently deranged programmer could write code that would destroy a constant object.  They decided that the second case was the lesser evil.  Requiring all constant objects to have indefinite lifetimes would be both inconvenient and inefficient.  For that matter, to be consistent, you would also have to forbid running the constructors of constant objects, because they too change object content, so you could never create a constant object in the first place.  So on the whole, it is most practical to exclude construction and destruction from the class of operations that are not allowed on constant objects.
0
Prashant SabnekarAVPCommented:
Do not think of constructors & distructors as an ordinary member functions. These are special member functions, one initializes and other deinitializes.
Any object can call distructor explicitly, irrespective to whether it is a const or a non const.
I do not find any strange thing in const object calling distructor explicitly.
If you have a problem with,
1. const obj calling distructor, let me tell you a basic thing any thing created has to be destroyed so distructor call is a must.
2. const obj calling distructor explicitly, here objects are allowed for this.

All the best
Prashant Sabnekar
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.