calling constructor when allocating an array

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

    #16
    Re: calling constructor when allocating an array

    Ron Natalie wrote:[color=blue][color=green][color=darkred]
    >>>> This is not a pointer array. It is a pointer to an array.
    >>>
    >>> Well it's a pointer to the first element of an array.[/color]
    >>
    >> Yes. This is the way it goes when we point to a part of the memory.
    >> We
    >> point to the beginning of it. Like a pointer to a double will point
    >> to its
    >> first byte. ;-)
    >>[/color]
    > No, pointers point to complete objects as far as the language is
    > concerend.
    > MyClass* points to one MyClass instance which happens to be the first
    > element of the array.[/color]

    SET PEDANTIC=OFF

    In any case: a pointer array (as far as I know English) is an array of
    pointers. I do not feel my description too misleading. It might not be
    pedantic to call it a pointer to an array but it does point to an array of
    MyClass instances.

    I understand that (strictly speaking) if I say pointer to an array one might
    say: OK, so if I then say ++ptr, then it will point to the next array. And
    of course this is not the case. :-)

    --
    WW aka Attila


    Comment

    • White Wolf

      #17
      Re: calling constructor when allocating an array

      Buster wrote:[color=blue][color=green][color=darkred]
      >>> A pointer to an array would look like this:
      >>> MyClass (* pointerArray) [NN];
      >>> // NN is a (compile-time) integral constant[/color]
      >>
      >> This is playing with the words.
      >>
      >> MyClass *pointerArray;
      >>
      >> will point to the array allocated by the new[] operator.[/color]
      >
      > Sorry, no. To the first element. I know what you mean,
      > but it isn't what you said.[/color]

      The start of the array is the first element.

      --
      WW aka Attila


      Comment

      • Buster

        #18
        Re: calling constructor when allocating an array

        [color=blue]
        > In any case: a pointer array (as far as I know English) is an array of
        > pointers. I do not feel my description too misleading. It might not be
        > pedantic to call it a pointer to an array but it does point to an array of
        > MyClass instances.
        >
        > I understand that (strictly speaking) if I say pointer to an array one might
        > say: OK, so if I then say ++ptr, then it will point to the next array. And
        > of course this is not the case. :-)[/color]

        Confusing = false;

        Yup. That's why in the standard it says that the value of an array
        new-expression is a pointer to the first element of the array, rather
        than saying it's a pointer to the array.

        What do you say when you _do_ mean 'pointer to an array'?

        In any case, I didn't mean to wind you up. Sorry.

        Regards,
        Buster.


        Comment

        • White Wolf

          #19
          Re: calling constructor when allocating an array

          Buster wrote:[color=blue][color=green]
          >> I understand that (strictly speaking) if I say pointer to an array
          >> one might say: OK, so if I then say ++ptr, then it will point to the
          >> next array. And of course this is not the case. :-)[/color]
          >
          > Confusing = false;
          >
          > Yup. That's why in the standard it says that the value of an array
          > new-expression is a pointer to the first element of the array, rather
          > than saying it's a pointer to the array.
          >
          > What do you say when you _do_ mean 'pointer to an array'?
          >
          > In any case, I didn't mean to wind you up. Sorry.[/color]

          I am programming from 1984. I have never needed to say or use a pointer to
          an array. So something along the lines of that bracketed nice declaration.
          I know how to write it and I never needed to use it. :-)

          --
          WW aka Attila


          Comment

          • Ron Natalie

            #20
            Re: calling constructor when allocating an array


            "White Wolf" <wolof@freemail .hu> wrote in message news:bka1v8$kpn $1@phys-news1.kolumbus. fi...
            [color=blue][color=green]
            > > No, pointers point to complete objects as far as the language is
            > > concerend.
            > > MyClass* points to one MyClass instance which happens to be the first
            > > element of the array.[/color]
            >
            > In any case: a pointer array (as far as I know English) is an array of
            > pointers. I do not feel my description too misleading. It might not be
            > pedantic to call it a pointer to an array but it does point to an array of
            > MyClass instances.[/color]

            I have no qualms with whether pointerArray is an array of pointer or
            pointer to an array. However, it the example given, you HAVE NEITHER.

            You are destined for trouble if you think pointers and arrays are synonymous.
            They are not. Pointers point to single objects.

            However my comments were specifically directed at the comment from attilla
            that said that a pointer might be thought of pointing to the first byte. This
            is not true. There's no rquirements that a non-char pointer even be able to
            address bytes. If people would stop assumingt the entire world is a freaking
            Pentium they'd understand the language a little better.


            Comment

            • Philipp

              #21
              Re: calling constructor when allocating an array

              > i think you're trying to do something like this:[color=blue]
              >
              > int N = 22;
              > // the ** makes the array of pointer not array of objects
              > MyClass **pointerArray;
              >
              > // crerate all the Pointer
              > pointerArray = new (MyClass*)[N];
              >
              > // create all the objects
              > for (int i=0; i< N; i++)
              > pointerArray[i] = new MyClass(i);[/color]

              Yes exactly! That's what I wanted to do and after thinking for 5 minutes by
              myself I figured it out...
              I just was confused that one of the ' * ' is for the array and the second
              one is for the actual pointers stored in the array.

              Thanks to all of you for your answers.
              Phil


              Comment

              • White Wolf

                #22
                Re: calling constructor when allocating an array

                Ron Natalie wrote:[color=blue]
                > I have no qualms with whether pointerArray is an array of pointer or
                > pointer to an array. However, it the example given, you HAVE
                > NEITHER.[/color]

                Yes, I missed the mistake in the code.
                [color=blue]
                > You are destined for trouble if you think pointers and arrays are
                > synonymous.
                > They are not. Pointers point to single objects.[/color]

                I do not think that and I have never said I did.
                [color=blue]
                > However my comments were specifically directed at the comment from
                > attilla
                > that said that a pointer might be thought of pointing to the first
                > byte.[/color]

                Look at the sig Ron. I *am* Attila. With an uppercase A, and pronounced
                Atilla. With an uppercase A/ ;-)
                [color=blue]
                > This is not true.[/color]

                Correction: this may not be true.
                [color=blue]
                > There's no rquirements that a non-char pointer even be
                > able to address bytes.[/color]

                But it is guaranteed that when converted to char* (or unsigned char* or
                signed char*) it will point to the first byte of the storage representing
                that object.
                [color=blue]
                > If people would stop assumingt the entire world is a
                > freaking
                > Pentium they'd understand the language a little better.[/color]

                If people would stop assuming what other people assume we would get less war
                and more beer to drink.

                --
                WW aka Attila


                Comment

                Working...