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

question about 'new'

Hi all,

MyClass Instance = NULL;
Instance = new MyClass();

and 'new' throws an exception.
is the value of Instance still NULL, or is it undefined?

I looked in MSDN, but could not really find out.

kind regards,
Bruno.
Nov 16 '05 #1
3 829
Bruno van Dooren wrote:

MyClass Instance = NULL;
Instance = new MyClass();

and 'new' throws an exception.
is the value of Instance still NULL, or is it undefined?


I'd think that the assignment wouldn't execute, because the exception
is thrown while it's evaluating the righthand side (before the value
to assign has been determined). Someone else should be able to give
you chapter and verse.

--
Craig Powers
MVP - Visual C++
Nov 16 '05 #2
Bruno van Dooren wrote:
MyClass Instance = NULL;
Instance = new MyClass();

and 'new' throws an exception.
is the value of Instance still NULL, or is it undefined?


The assignmend will not execute, so therefor the old value is still valid
(NULL).

--
Greetings
Jochen

Do you need a memory-leak finder ?
http://www.codeproject.com/tools/leakfinder.asp
Nov 16 '05 #3
Craig Powers wrote:
Bruno van Dooren wrote:

MyClass Instance = NULL;
MyClass* Instance = 0;
Instance = new MyClass();

and 'new' throws an exception.
is the value of Instance still NULL, or is it undefined?


I'd think that the assignment wouldn't execute, because the exception
is thrown while it's evaluating the righthand side (before the value
to assign has been determined). Someone else should be able to give
you chapter and verse.


That's absolutely correct. Normal C++ expression rules cover this: the
lefthand side of an assignment cannot be assigned to until the righthand
side has been evaluated, and a new expression isn't fully evaluated until
allocation has succeeded or a constructor has run to completion. Any
exception thrown from the allocation function or the constructor prevents
the expression from being fully evaluated, so the left hand side of the
assignment is guaranteed to have not been assigned.

-cd
Nov 16 '05 #4

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

Similar topics

3
by: Stevey | last post by:
I have the following XML file... <?xml version="1.0"?> <animals> <animal> <name>Tiger</name> <questions> <question index="0">true</question> <question index="1">true</question> </questions>
20
by: __PPS__ | last post by:
Hello everybody in a quiz I had a question about dangling pointer: "What a dangling pointer is and the danger of using it" My answer was: "dangling pointer is a pointer that points to some...
10
by: glenn | last post by:
I am use to programming in php and the way session and post vars are past from fields on one page through to the post page automatically where I can get to their values easily to write to a...
0
by: | last post by:
I have a question about spawning and displaying subordinate list controls within a list control. I'm also interested in feedback about the design of my search application. Lots of code is at the...
2
by: Ken Fine | last post by:
I want to add the security question and answer security feature to the ChangePassword control. I am aware that this functionality is built into the PasswordRecovery tool. I have implemented the...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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,...

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.