473,473 Members | 2,319 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

object destruction

EN
Hi.

I've small problem :
I've two objects, each from another class:
example object a from class A and b from B.
I method from class A :
a.setValue() I made object b:
B *b = new B();

What is happen when in main program I invoke delete to object a,
object b is destroy to???

example:

int main(){
A *a = new A();
a->setValue(4);
delete a;
}

Thanks in advice
EN
Jul 23 '05 #1
3 1230

"EN" <fs@dd.pl> wrote in message
Hi.

I've small problem :
I've two objects, each from another class:
example object a from class A and b from B.
I method from class A :
a.setValue() I made object b:
B *b = new B();

What is happen when in main program I invoke delete to object a,
object b is destroy to???

example:

int main(){
A *a = new A();
a->setValue(4);
delete a;
}

Your language is not clear but b won't get destroyed when a is deleted. You
have to delete it explicitly.

Sharad

Jul 23 '05 #2
EN wrote:
Hi.

I've small problem :
I've two objects, each from another class:
example object a from class A and b from B.
Your example code below only contains the former. Where is object b?
I method from class A :
a.setValue() I made object b:
B *b = new B();

What is happen when in main program I invoke delete to object a,
object b is destroy to???
Well, when you got it from new, it has to be deleted explicitly.
example:

int main(){
A *a = new A();
a->setValue(4);
delete a;
}


Jul 23 '05 #3
On Tue, 2005-03-15 at 11:57 +0100, EN wrote:
What is happen when in main program I invoke delete to object a,
object b is destroy to???


No, unless you specify it in a constructor. A common design practice I
use is delete an object in the same class as it is created. It avoids
confusion and keeps pointer management centralized.

Leon Mergen
http://www.solatis.com/

Jul 23 '05 #4

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

Similar topics

6
by: Virendra Verma | last post by:
This sounds weird, but I am looking for separate behaviors for destruction of a const and non-const object. I am trying to develop a smart/auto pointer class for writing objects to disk...
6
by: Sowen | last post by:
hi, I have the following code object obj_1; object obj_2; object obj_3; object *objs = { &obj_1, &obj_2, &obj_3 };
5
by: Rich P | last post by:
I have to read data from an external source, massage the data, concatenate it to one long string, then write it to a textfile. So I am experimenting with the StringBuilder object. I append the...
9
by: plahey | last post by:
I have been dabbling in Python for a while now. One of the things that really appeals to me is that I can seem to be able to use C++-style RAII idioms to deal with resource management issues. ...
15
by: cedgington | last post by:
I wanted to take advantage of the large set of functionality offered by the framework, so for my latest project I'm using managed C++ with .NET v2. I'm using the gcnew operator in two different...
12
by: Belebele | last post by:
Suppose that a class A depends on class B because an object of class B is passed into A's constructor. See below: class B { ... }; class A { public: A(B const& b); ... };
6
by: Pablo | last post by:
Hello, I am writing a windows application using C++ and BorlandBuilder 6 compiler. It is an event driven program and I need to create objects of some classes written by me. One of the classes...
5
by: Frederick Gotham | last post by:
If we have a simple class such as follows: #include <string> struct MyStruct { std::string member; MyStruct(unsigned const i) {
4
by: gg9h0st | last post by:
i worte a simple code below. ------------------------------------------------------------------------------------ #include "stdafx.h" class Object { public: int a;
14
by: Jeroen | last post by:
Hi all, I've got a question about writing a library. Let me characterize that library by the following: * there is a class A which is available to the user * there is a class B that is used...
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
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
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...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.