473,412 Members | 3,015 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,412 software developers and data experts.

C++: destructor and delete

Hi,

Statement 1: "A dynamically created local object will call it's destructor
method when it goes out of scope when a procedure returms"

Agree.
Statement 2: "A dynamically created object will call it's destructor when it
is made a target of a delete".

Does not make sense to me. Would not this result in an endless loop? (ie.
delete calls destructor and within destructor it calls delete, which in turn
calls the destructor again and so on....)

Any comments appreciated.

asasas

Jul 19 '05
52 26936

"Andrey Tarasevich" <an**************@hotmail.com> wrote in message
news:vl***********@news.supernews.com...
jeffc wrote:
...
Fine Ron, be pedantic if you insist. Stroustrup calls that a "simple and low-level notion of an object" and warns not to confuse it with the notion of a class object, which is what you've done - confuse things. Here's the original quote from the OP:

"> An object will always have a constructor and a destructor. If either is not
defined, they will be created for you implicitly. Since pointers are objects
too, they will have a constructor and destructor."


You go ahead and correct him and I'm sure you can come up with something
better than I did (I'm at a loss as to why you'd argue with my reply, rather than with his statement.)
...


It's been said many times here and in many other places, that TC++PL
book uses alternative non-standard terminology. Formally speaking, from
the standard C++ point of view, the above statement and a number of
other statements made in TC++PL are _completely_ _incorrect_.

It is not a matter of "correcting" or "not correcting" Mr. Stroustrup.


I'm talking about correcting the OP, not Mr. Stroustrup.
This forum, by default, uses the standard terminology. If you prefer to
use the one from TC++PL, you should accompany you messages with the
corresponding remark, to avoid unnecessary confusion.


Standard OO terminology is not unclear on the meaning of "object".
Jul 19 '05 #51

"Andrey Tarasevich" <an**************@hotmail.com> wrote in message
news:vl************@news.supernews.com...

Yes, there is. But I don't see how it is supposed to prove your point.
You were talking about "objects". Now your are talking about "built-in
types" and "instances of a class". Where is the connection?


I really don't know what bone you guys are trying to pick. The original
poster wrote
"An object will always have a constructor and a destructor. If either is not
defined, they will be created for you implicitly. Since pointers are objects
too, they will have a constructor and destructor."

I say he's wrong. If you want to argue with me about that, EOT. Otherwise
correct that statement any way you see fit.
Jul 19 '05 #52

"jeffc" <no****@nowhere.com> wrote in message news:3f********@news1.prserv.net...
I really don't know what bone you guys are trying to pick. The original
poster wrote
"An object will always have a constructor and a destructor. If either is not
defined, they will be created for you implicitly. Since pointers are objects
too, they will have a constructor and destructor."
As far as the C++ standard goes, the only thing that is right above is that
pointers are objects. Objects do not necessarily have constructors and destructors.
Only classes have them, pointers and other non-class types do not.

I say he's wrong. If you want to argue with me about that, EOT. Otherwise
correct that statement any way you see fit.


You're right. He's wrong.
Jul 19 '05 #53

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

Similar topics

6
by: Alexander Stippler | last post by:
Hi, I have some question about the usage of delete. I have some reference counted classes, all derived from SharedObject. It's destructor looks like this: ~SharedObject() { if...
11
by: Stub | last post by:
Please answer my questions below - thanks! 1. Why "Derived constructor" is called but "Derived destructor" not in Case 1 since object B is new'ed from Derived class? 2. Why "Derived destructor"...
14
by: Timothy Madden | last post by:
Hello I have a linked list of object of a class. I thought it would be nice to have the destructor delete the whole list when I delete just the first element. I don't want to recursivly destroy...
20
by: frs | last post by:
For memory economization, I need to get rid if the virtual destructor. Under this constraint I get caught up in a design, where I need to call a destructor of a derived class from a base class....
35
by: Peter Oliphant | last post by:
I'm programming in VS C++.NET 2005 using cli:/pure syntax. In my code I have a class derived from Form that creates an instance of one of my custom classes via gcnew and stores the pointer in a...
7
by: | last post by:
Hi, From 11.11 here, I know that member objects get their dtor's called autmatically: http://www.parashift.com/c++-faq-lite/dtors.html#faq-11.11 What if I have a pointer to a member object?...
5
by: junw2000 | last post by:
I use the code below to study delete and destructor. #include <iostream> using namespace std; struct A { virtual ~A() { cout << "~A()" << endl; }; //LINE1 void operator delete(void* p) {...
23
by: Ben Voigt | last post by:
I have a POD type with a private destructor. There are a whole hierarchy of derived POD types, all meant to be freed using a public member function Destroy in the base class. I get warning C4624....
9
by: rohits123 | last post by:
I have an overload delete operator as below ////////////////////////////////// void operator delete(void* mem,int head_type) { mmHead local_Head = CPRMemory::GetMemoryHead(head_type);...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.