Why doesn't nothrow work?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dustan

    Why doesn't nothrow work?

    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?

  • Victor Bazarov

    #2
    Re: Why doesn't nothrow work?

    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


    Comment

    • Dustan

      #3
      Re: Why doesn't nothrow work?

      On May 29, 12:02 pm, "Victor Bazarov" <v.Abaza...@com Acast.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

      Comment

      • red floyd

        #4
        Re: Why doesn't nothrow work?

        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>?

        Comment

        • Zeppe

          #5
          Re: Why doesn't nothrow work?

          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

          Comment

          • Dustan

            #6
            Re: Why doesn't nothrow work?

            On May 29, 12:46 pm, Zeppe
            <zep_p@.remove. all.this.long.c omment.yahoo.it wrote:
            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.c om/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.

            Comment

            • Victor Bazarov

              #7
              Re: Why doesn't nothrow work?

              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(althoug h 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


              Comment

              • red floyd

                #8
                Re: Why doesn't nothrow work?

                Dustan wrote:
                On May 29, 12:46 pm, Zeppe
                <zep_p@.remove. all.this.long.c omment.yahoo.it wrote:
                >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.c om/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
                >technicaliti es 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 <memoryworkin g is mere coincidence. Your implementation' s
                version of <memoryreferenc es <new>. Per the Standard 20.4, <memory>
                does not define nothrow. It's defined in <newper 18.4/1.

                Comment

                • Zeppe

                  #9
                  Re: Why doesn't nothrow work?

                  red floyd wrote:
                  Dustan wrote:
                  >Thanks to red floyd and Zeppe for their responses. Both <newand
                  ><memoryworke d, which I must admit is only further confusing for me;
                  >I guess I still have quite a ways to go.
                  >>
                  >
                  #include <memoryworkin g is mere coincidence. Your implementation' s
                  version of <memoryreferenc es <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

                  Comment

                  • red floyd

                    #10
                    Re: Why doesn't nothrow work?

                    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 <memoryworkin g is mere coincidence. Your implementation' s
                    >version of <memoryreferenc es <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.

                    Comment

                    • Zeppe

                      #11
                      Re: Why doesn't nothrow work?

                      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

                      Comment

                      • Dustan

                        #12
                        Re: Why doesn't nothrow work?

                        On May 30, 3:54 am, Zeppe
                        <zep_p@.remove. all.this.long.c omment.yahoo.it wrote:
                        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

                        Comment

                        • Zeppe

                          #13
                          Re: Why doesn't nothrow work?

                          Dustan wrote:
                          On May 30, 3:54 am, Zeppe
                          <zep_p@.remove. all.this.long.c omment.yahoo.it wrote:
                          >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

                          Comment

                          • Pete Becker

                            #14
                            Re: Why doesn't nothrow work?

                            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 "profession al" 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)

                            Comment

                            • Dustan

                              #15
                              Re: Why doesn't nothrow work?

                              On May 30, 10:57 am, Pete Becker <p...@versatile coding.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 "profession al" 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)

                              Comment

                              Working...