By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,018 Members | 870 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,018 IT Pros & Developers. It's quick & easy.

Why doesn't nothrow work?

P: n/a
This is the biggie that has been keeping me from even trying to use C+
+ for more than about 10 seconds: it doesn't work. I've been able to
get java and (of course) python programs to compile and run, but not C+
+.

I copied a program from http://www.cplusplus.com/doc/tutorial/dynamic.html
(if that's a bad place to go for a tutorial, feel free to direct me
elsewhere), and the following line gets an error:

p= new (nothrow) int[i];

Here are the errors I get (all on line 11, the one above):
`nothrow' undeclared (first use this function)
(Each undeclared identifier is reported only once
for each function it appears in.)
confused by earlier errors, bailing out

It seems odd to me that it's calling 'nothrow' a function; is (XXX)
really valid functional notation in C++? I thought that syntax was
reserved for casts.

I'm using Bloodshed Dev-C++ Version 4, on Microsoft Windows XP Version
5.1.2600. Any ideas as to what my problem might be?

May 29 '07 #1
Share this Question
Share on Google+
16 Replies


P: n/a
Dustan wrote:
This is the biggie that has been keeping me from even trying to use C+
+ for more than about 10 seconds: it doesn't work. I've been able to
get java and (of course) python programs to compile and run, but not
C+ +.

I copied a program from
http://www.cplusplus.com/doc/tutorial/dynamic.html (if that's a bad
place to go for a tutorial, feel free to direct me elsewhere), and
the following line gets an error:

p= new (nothrow) int[i];
Have you tried

p = new (std::nothrow) int[i];

?
>
Here are the errors I get (all on line 11, the one above):
`nothrow' undeclared (first use this function)
(Each undeclared identifier is reported only once
for each function it appears in.)
confused by earlier errors, bailing out

It seems odd to me that it's calling 'nothrow' a function; is (XXX)
really valid functional notation in C++? I thought that syntax was
reserved for casts.

I'm using Bloodshed Dev-C++ Version 4, on Microsoft Windows XP Version
5.1.2600. Any ideas as to what my problem might be?
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
May 29 '07 #2

P: n/a
On May 29, 12:02 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
Dustan wrote:
This is the biggie that has been keeping me from even trying to use C+
+ for more than about 10 seconds: it doesn't work. I've been able to
get java and (of course) python programs to compile and run, but not
C+ +.
I copied a program from
http://www.cplusplus.com/doc/tutorial/dynamic.html(if that's a bad
place to go for a tutorial, feel free to direct me elsewhere), and
the following line gets an error:
p= new (nothrow) int[i];

Have you tried

p = new (std::nothrow) int[i];

?
Thanks for the response.

Yes I had tried that, and no, it didn't work. I didn't get the exact
same error messages, but it conveyed the same problem:
`::nothrow' undeclared (first use here)
confused by earlier errors, bailing out
Here are the errors I get (all on line 11, the one above):
`nothrow' undeclared (first use this function)
(Each undeclared identifier is reported only once
for each function it appears in.)
confused by earlier errors, bailing out
It seems odd to me that it's calling 'nothrow' a function; is (XXX)
really valid functional notation in C++? I thought that syntax was
reserved for casts.
I'm using Bloodshed Dev-C++ Version 4, on Microsoft Windows XP Version
5.1.2600. Any ideas as to what my problem might be?

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask

May 29 '07 #3

P: n/a
Dustan wrote:
This is the biggie that has been keeping me from even trying to use C+
+ for more than about 10 seconds: it doesn't work. I've been able to
get java and (of course) python programs to compile and run, but not C+
+.

I copied a program from http://www.cplusplus.com/doc/tutorial/dynamic.html
(if that's a bad place to go for a tutorial, feel free to direct me
elsewhere), and the following line gets an error:

p= new (nothrow) int[i];

Here are the errors I get (all on line 11, the one above):
`nothrow' undeclared (first use this function)
(Each undeclared identifier is reported only once
for each function it appears in.)
confused by earlier errors, bailing out
Did you #include <new>?
May 29 '07 #4

P: n/a
Dustan wrote:
This is the biggie that has been keeping me from even trying to use C+
+ for more than about 10 seconds: it doesn't work. I've been able to
get java and (of course) python programs to compile and run, but not C+
+.
C++ it's a little bit tricky but when you know how to use it it's very
powerful, more than python or java. It's worth the time ;)
I copied a program from http://www.cplusplus.com/doc/tutorial/dynamic.html
(if that's a bad place to go for a tutorial, feel free to direct me
elsewhere), and the following line gets an error:
I don't know exactly, many tutorials in the net have got slight errors
or imperfections.
>
p= new (nothrow) int[i];

Here are the errors I get (all on line 11, the one above):
`nothrow' undeclared (first use this function)
(Each undeclared identifier is reported only once
for each function it appears in.)
confused by earlier errors, bailing out

It seems odd to me that it's calling 'nothrow' a function; is (XXX)
really valid functional notation in C++? I thought that syntax was
reserved for casts.
Well, it's not. The brackets are just dummy, and then ignored, and the
token is interpreted as a function reference. But those are
technicalities for a learner, in my opinion. You will learn, with the
experience, to do this:

1) read the error: `nothrow' undeclared
2) why is undeclared? it's standard library! so, try std::nothrow
3) error: ‘nothrow’ is not a member of ‘std’... Damn!
4) why it is not? because everything in c++ has to be defined somewhere,
and all the things of the standard library are defined in a header file
5) pick a book, and check out std::nothrow
6) #include <memory>
7) it works!

;)

Regards,

Zeppe
May 29 '07 #5

P: n/a
On May 29, 12:46 pm, Zeppe
<zep_p@.remove.all.this.long.comment.yahoo.itwrote :
Dustan wrote:
This is the biggie that has been keeping me from even trying to use C+
+ for more than about 10 seconds: it doesn't work. I've been able to
get java and (of course) python programs to compile and run, but not C+
+.

C++ it's a little bit tricky but when you know how to use it it's very
powerful, more than python or java. It's worth the time ;)
Yeah... they say that exact same thing over at c.l.python and
c.l.java. I get the feeling everyone's biased or something. ;)
I copied a program fromhttp://www.cplusplus.com/doc/tutorial/dynamic.html
(if that's a bad place to go for a tutorial, feel free to direct me
elsewhere), and the following line gets an error:

I don't know exactly, many tutorials in the net have got slight errors
or imperfections.
p= new (nothrow) int[i];
Here are the errors I get (all on line 11, the one above):
`nothrow' undeclared (first use this function)
(Each undeclared identifier is reported only once
for each function it appears in.)
confused by earlier errors, bailing out
It seems odd to me that it's calling 'nothrow' a function; is (XXX)
really valid functional notation in C++? I thought that syntax was
reserved for casts.

Well, it's not. The brackets are just dummy, and then ignored, and the
token is interpreted as a function reference. But those are
technicalities for a learner, in my opinion. You will learn, with the
experience, to do this:

1) read the error: `nothrow' undeclared
2) why is undeclared? it's standard library! so, try std::nothrow
3) error: 'nothrow' is not a member of 'std'... Damn!
4) why it is not? because everything in c++ has to be defined somewhere,
and all the things of the standard library are defined in a header file
5) pick a book, and check out std::nothrow
6) #include <memory>
7) it works!

;)

Regards,

Zeppe
Thanks to red floyd and Zeppe for their responses. Both <newand
<memoryworked, which I must admit is only further confusing for me;
I guess I still have quite a ways to go.

May 29 '07 #6

P: n/a
Dustan wrote:
[..]
Thanks to red floyd and Zeppe for their responses. Both <newand
<memoryworked, which I must admit is only further confusing for me;
Why is it confusing you? 'nothrow' is a symbol. It needs to be
defined; and it is, in <new>. It is conceivable that <newis
included into <memory(although it doesn't have to be), so when
you include <memory>, you also implicitly include <new(which is
what you actually need for 'nothrow').

It's similar to how 'NULL' is defined pretty much any time you pull
in *any* standard header (probably), while its actual residence is
in <cstddef>, <cstring>, <cstdio>, <ctime>, or <cwchar>. Don't
rely on NULL's definition to exist all the time, do include one of
the required headers for it.
I guess I still have quite a ways to go.
Most of us do, as well.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
May 29 '07 #7

P: n/a
Dustan wrote:
On May 29, 12:46 pm, Zeppe
<zep_p@.remove.all.this.long.comment.yahoo.itwrote :
>Dustan wrote:
>>This is the biggie that has been keeping me from even trying to use C+
+ for more than about 10 seconds: it doesn't work. I've been able to
get java and (of course) python programs to compile and run, but not C+
+.
C++ it's a little bit tricky but when you know how to use it it's very
powerful, more than python or java. It's worth the time ;)

Yeah... they say that exact same thing over at c.l.python and
c.l.java. I get the feeling everyone's biased or something. ;)
>>I copied a program fromhttp://www.cplusplus.com/doc/tutorial/dynamic.html
(if that's a bad place to go for a tutorial, feel free to direct me
elsewhere), and the following line gets an error:
I don't know exactly, many tutorials in the net have got slight errors
or imperfections.
>> p= new (nothrow) int[i];
Here are the errors I get (all on line 11, the one above):
`nothrow' undeclared (first use this function)
(Each undeclared identifier is reported only once
for each function it appears in.)
confused by earlier errors, bailing out
It seems odd to me that it's calling 'nothrow' a function; is (XXX)
really valid functional notation in C++? I thought that syntax was
reserved for casts.
Well, it's not. The brackets are just dummy, and then ignored, and the
token is interpreted as a function reference. But those are
technicalities for a learner, in my opinion. You will learn, with the
experience, to do this:

1) read the error: `nothrow' undeclared
2) why is undeclared? it's standard library! so, try std::nothrow
3) error: 'nothrow' is not a member of 'std'... Damn!
4) why it is not? because everything in c++ has to be defined somewhere,
and all the things of the standard library are defined in a header file
5) pick a book, and check out std::nothrow
6) #include <memory>
7) it works!

;)

Regards,

Zeppe

Thanks to red floyd and Zeppe for their responses. Both <newand
<memoryworked, which I must admit is only further confusing for me;
I guess I still have quite a ways to go.
#include <memoryworking is mere coincidence. Your implementation's
version of <memoryreferences <new>. Per the Standard 20.4, <memory>
does not define nothrow. It's defined in <newper 18.4/1.
May 29 '07 #8

P: n/a
red floyd wrote:
Dustan wrote:
>Thanks to red floyd and Zeppe for their responses. Both <newand
<memoryworked, which I must admit is only further confusing for me;
I guess I still have quite a ways to go.

#include <memoryworking is mere coincidence. Your implementation's
version of <memoryreferences <new>. Per the Standard 20.4, <memory>
does not define nothrow. It's defined in <newper 18.4/1.


Citing the standard, I guess, is to simplify the things to the beginner,
isn't it? Anyway, you caught me, I didn't really checked up in the book ^^

Regards,

Zeppe
May 29 '07 #9

P: n/a
Zeppe wrote:
red floyd wrote:
>Dustan wrote:
>>Thanks to red floyd and Zeppe for their responses. Both <newand
<memoryworked, which I must admit is only further confusing for me;
I guess I still have quite a ways to go.

#include <memoryworking is mere coincidence. Your implementation's
version of <memoryreferences <new>. Per the Standard 20.4, <memory>
does not define nothrow. It's defined in <newper 18.4/1.

Citing the standard, I guess, is to simplify the things to the beginner,
isn't it? Anyway, you caught me, I didn't really checked up in the book ^^
No, it's more to explain *why* #include <memoryis the wrong answer.
When in doubt, "because the Standard says so", is a good answer.
May 30 '07 #10

P: n/a
red floyd wrote:
Zeppe wrote:
>Citing the standard, I guess, is to simplify the things to the beginner,
isn't it? Anyway, you caught me, I didn't really checked up in the book ^^

No, it's more to explain *why* #include <memoryis the wrong answer.
When in doubt, "because the Standard says so", is a good answer.
I hope you will agree that it's unlikely that the OP will read the
standard... anyway, I didn't want to argue about that, sure citing the
standard is always the best way to solve a doubt (for me, it would have
been enough "nothrow is defined in new, not in memory", and I would have
checked it out), but sometimes, particularly when a beginner asks
something, it can sound a little bit harsh, you know, bumptious.

Just my personal impression, though..

Regards,

Zeppe
May 30 '07 #11

P: n/a
On May 30, 3:54 am, Zeppe
<zep_p@.remove.all.this.long.comment.yahoo.itwrote :
red floyd wrote:
Zeppe wrote:
Citing the standard, I guess, is to simplify the things to the beginner,
isn't it? Anyway, you caught me, I didn't really checked up in the book ^^
No, it's more to explain *why* #include <memoryis the wrong answer.
When in doubt, "because the Standard says so", is a good answer.

I hope you will agree that it's unlikely that the OP will read the
standard...
Show me the standard and I'll look at it. It looks like it'll help me
break through some of the issues I'm experiencing.
anyway, I didn't want to argue about that, sure citing the
standard is always the best way to solve a doubt (for me, it would have
been enough "nothrow is defined in new, not in memory", and I would have
checked it out), but sometimes, particularly when a beginner asks
something, it can sound a little bit harsh, you know, bumptious.

Just my personal impression, though..

Regards,

Zeppe

May 30 '07 #12

P: n/a
Dustan wrote:
On May 30, 3:54 am, Zeppe
<zep_p@.remove.all.this.long.comment.yahoo.itwrote :
>red floyd wrote:
>>Zeppe wrote:
Citing the standard, I guess, is to simplify the things to the beginner,
isn't it? Anyway, you caught me, I didn't really checked up in the book ^^
No, it's more to explain *why* #include <memoryis the wrong answer.
When in doubt, "because the Standard says so", is a good answer.
I hope you will agree that it's unlikely that the OP will read the
standard...

Show me the standard and I'll look at it. It looks like it'll help me
break through some of the issues I'm experiencing.
The standard is not very easy to look at, much better a good book for
the beginners (like the stroustrup). It isn't even available for free.
The draft is available, and it's quite close to the actual standard:
ftp://ftp.research.att.com/dist/c++std/WP/CD2

Regards,

Zeppe
May 30 '07 #13

P: n/a
Zeppe wrote:
>
The standard is not very easy to look at, much better a good book for
the beginners (like the stroustrup). It isn't even available for free.
The draft is available, and it's quite close to the actual standard:
ftp://ftp.research.att.com/dist/c++std/WP/CD2
It's close to the 1998 standard. It's a long ways from the 2003
standard. Why is it that so many "professional" programmers aren't
willing to pay $30 for current information?

--

-- Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com)
Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." (www.petebecker.com/tr1book)
May 30 '07 #14

P: n/a
On May 30, 10:57 am, Pete Becker <p...@versatilecoding.comwrote:
Zeppe wrote:
The standard is not very easy to look at, much better a good book for
the beginners (like the stroustrup). It isn't even available for free.
The draft is available, and it's quite close to the actual standard:
ftp://ftp.research.att.com/dist/c++std/WP/CD2

It's close to the 1998 standard. It's a long ways from the 2003
standard. Why is it that so many "professional" programmers aren't
willing to pay $30 for current information?
Because I'm not professional???
--

-- Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com)
Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." (www.petebecker.com/tr1book)

May 30 '07 #15

P: n/a
On Tue, 29 May 2007 09:56:13 -0700, Dustan wrote:
This is the biggie that has been keeping me from even trying to use C+ +
for more than about 10 seconds: it doesn't work. I've been able to get
java and (of course) python programs to compile and run, but not C+ +.

I copied a program from
http://www.cplusplus.com/doc/tutorial/dynamic.html (if that's a bad
place to go for a tutorial, feel free to direct me elsewhere), and the
following line gets an error:

p= new (nothrow) int[i];

Here are the errors I get (all on line 11, the one above):
`nothrow' undeclared (first use this function) (Each undeclared
identifier is reported only once for each function it appears in.)
confused by earlier errors, bailing out

It seems odd to me that it's calling 'nothrow' a function; is (XXX)
really valid functional notation in C++? I thought that syntax was
reserved for casts.
It is not calling `nothrow' a function. "first use this function" is
short for "the given position is the first use of this particular
undeclared identifier in this function". And the actual function name is
also part of the error message.

--
Markus Schoder
May 30 '07 #16

P: n/a
In article <11*********************@k79g2000hse.googlegroups. com>,
Du**********@gmail.com says...
On May 29, 12:46 pm, Zeppe
<zep_p@.remove.all.this.long.comment.yahoo.itwrote :
Dustan wrote:
This is the biggie that has been keeping me from even trying to use C+
+ for more than about 10 seconds: it doesn't work. I've been able to
get java and (of course) python programs to compile and run, but not C+
+.
C++ it's a little bit tricky but when you know how to use it it's very
powerful, more than python or java. It's worth the time ;)

Yeah... they say that exact same thing over at c.l.python and
c.l.java. I get the feeling everyone's biased or something. ;)
It's necessarily that anybody's biased -- it's just that "powerful"
doesn't really mean much about a programming language. C++ gives lots of
control at a finer level of detail than most other languages. In
exchange for that, it _requires_ you to control more of what's going on,
even in cases where most other languages provide a single option (or
perhaps a default option) that usually makes sense.

[ ... ]
Thanks to red floyd and Zeppe for their responses. Both <newand
<memoryworked, which I must admit is only further confusing for me;
I guess I still have quite a ways to go.
<newis where the standard says nothrow is defined. The C++ standard
allows inclusion of one standard header to also have the effect of
including any other standard headers the implementation chooses.

That's undoubtedly what's happening in the case of including <memory--
on your implementation, it's including <newindirectly; it's not
required to do so, however, so what you want to include is <new>.

--
Later,
Jerry.

The universe is a figment of its own imagination.
Jun 3 '07 #17

This discussion thread is closed

Replies have been disabled for this discussion.