473,396 Members | 1,936 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,396 software developers and data experts.

Instance creation

Hello,
I get the same o/p for the 2 pieces of code below:
Base *b = new Base ;
b->test() ;
delete b ;

vs just saying:
(new Base)->test() ;

In the second case, how is the object created and what instance of the
object do we have to "delete" at the end of the program. It's a very
fundamental thing which I seem to be getting confused at. Inputs are
welcome.

Thanks

Aug 20 '05 #1
2 1455
da*********@yahoo.com wrote:
Hello,
I get the same o/p for the 2 pieces of code below:
Base *b = new Base ;
b->test() ;
delete b ;

vs just saying:
(new Base)->test() ;
What is an "o/p"?
In the second case, how is the object created
Just the same as in the first case. Dynamically with new.
and what instance of the object do we have to "delete" at the end of the
program.


Well, you didn't store the pointer to it, so unless Base's constructor or
the test() member function stores it somewhere, that pointer is lost and
you cannot delete the object.

Aug 20 '05 #2
o/p as in output.
Well, you didn't store the pointer to it, so unless Base's
constructor or the test() member function stores it
somewhere, that pointer is lost and you cannot delete the
object.


hmm.. Thanks for the suggestion, I will ponder over it :)

Aug 20 '05 #3

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

Similar topics

14
by: Sridhar R | last post by:
Consider the code below, class Base(object): pass class Derived(object): def __new__(cls, *args, **kwds): # some_factory returns an instance of Base # and I have to derive from this...
6
by: Andre Meyer | last post by:
Hi all I have been searching everywhere for this, but have not found a solution, yet. What I need is to create an object that is an instance of a class (NOT a class instance!) of which I only...
18
by: Steve Barnett | last post by:
I want to ensure that there is only ever one instance of my app running on a single PC at any time. I understand that I can achieve this by using a mutex and, if I can't take ownership of the...
1
by: Anurag | last post by:
Hello Folks, Here's wishing you MERRY CHRISTMAS and Festive seasons's greeting!! Now this has been bugging me for quite a while and I seek your help in setting my mind to peace. As part of DB2...
5
by: Russell Warren | last post by:
I just ran across a case which seems like an odd exception to either what I understand as the "normal" variable lookup scheme in an instance/object heirarchy, or to the rules regarding variable...
8
by: al pacino | last post by:
hi, i want to know how does c++ compiler prohibits the creation of instance of an abstract class? i think it must be checking on the vtable entry if there is an entry with zero(indicting...
5
by: JH | last post by:
Hi I found that a type/class are both a subclass and a instance of base type "object". It conflicts to my understanding that: 1.) a type/class object is created from class statement 2.) a...
9
by: glomde | last post by:
Hi I wonder if you can set what subclass a class should have at instance creation. The problem is that I have something like: class CoreLang(): def AssignVar(self, var, value): pass class...
1
by: mitrofun63 | last post by:
Hi, All I have trouble with db2 instance creation (DB2 9.1.2 on AIX 5.3) When i run command for instance creation : ../db2icrt -a SERVER -p 50000 -s ese -u db2fenc1 db2inst1 a reciveve...
0
tlhintoq
by: tlhintoq | last post by:
My project involves reading magstripe cards, capturing an ID number, then spinning off to do some other things including taking a photograph. 99% of this is done and good. All early phases of work...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.