containers of arrays?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Stephen J. Fromm

    containers of arrays?

    I take it I cannot form a container of an array type? For example,
    stack<string[3]> parentStack;

    TIA,

    sjfromm
  • Victor Bazarov

    #2
    Re: containers of arrays?

    "Stephen J. Fromm" <stephen.fromm@ verizon.net> wrote...[color=blue]
    > I take it I cannot form a container of an array type? For example,
    > stack<string[3]> parentStack;[/color]

    Yes.


    Comment

    • John Dibling

      #3
      Re: containers of arrays?

      On 29 Jul 2003 10:18:57 -0700, stephen.fromm@v erizon.net (Stephen J.
      Fromm) wrote:
      [color=blue]
      >I take it I cannot form a container of an array type? For example,
      > stack<string[3]> parentStack;
      >
      >TIA,
      >
      >sjfromm[/color]

      You can have containers of arrays, but the declaration youv'e posted
      above is faulty. Youv'e declared a stack where each element is 3
      strings. This is fine in principle, but probaly what you should do is
      declare a struct that defines the stack elements, then declare the
      stack as a stack of those things, like this:

      struct STRINGS
      {
      string m_Strings[3];
      }; // STRINGS

      int main()
      {
      std::stack<STRI NGS> stk;
      return 0;
      }

      </dib>
      John Dibling
      Witty banter omitted for your protection

      Comment

      • Rolf Magnus

        #4
        Re: containers of arrays?

        John Dibling wrote:
        [color=blue]
        > On 29 Jul 2003 10:18:57 -0700, stephen.fromm@v erizon.net (Stephen J.
        > Fromm) wrote:
        >[color=green]
        >>I take it I cannot form a container of an array type? For example,
        >> stack<string[3]> parentStack;
        >>
        >>TIA,
        >>
        >>sjfromm[/color]
        >
        > You can have containers of arrays,[/color]

        No, you can't.
        [color=blue]
        > but the declaration youv'e posted
        > above is faulty. Youv'e declared a stack where each element is 3
        > strings. This is fine in principle,[/color]

        No, it's not. Arrays are not assignable and as such, they cannot be used
        as elements of standard containers. The above code should not be
        accepted by your C++ compiler.
        [color=blue]
        > but probaly what you should do is
        > declare a struct that defines the stack elements, then declare the
        > stack as a stack of those things, like this:
        >
        > struct STRINGS
        > {
        > string m_Strings[3];
        > }; // STRINGS
        >
        > int main()
        > {
        > std::stack<STRI NGS> stk;
        > return 0;
        > }[/color]

        That would work.

        Comment

        • Stephen J. Fromm

          #5
          Re: containers of arrays?

          "Victor Bazarov" <v.Abazarov@att Abi.com> wrote in message news:<vidcq25k0 vspdb@corp.supe rnews.com>...[color=blue]
          > "Stephen J. Fromm" <stephen.fromm@ verizon.net> wrote...[color=green]
          > > I take it I cannot form a container of an array type? For example,
          > > stack<string[3]> parentStack;[/color]
          >
          > Yes.[/color]

          Victor,

          Yes, I can form, or yes, I cannot form?

          Comment

          • Stephen J. Fromm

            #6
            Re: containers of arrays?

            John Dibling <dib@substitute _my_full_last_n ame_here.com> wrote in message news:<n3bdiv8fi 4d777210ten38kq bhmlu2sodf@4ax. com>...[color=blue]
            > On 29 Jul 2003 10:18:57 -0700, stephen.fromm@v erizon.net (Stephen J.
            > Fromm) wrote:[/color]

            Thanks for your reply.
            [color=blue][color=green]
            > >I take it I cannot form a container of an array type? For example,
            > > stack<string[3]> parentStack;
            > >
            > >TIA,
            > >
            > >sjfromm[/color]
            >
            > You can have containers of arrays, but the declaration youv'e posted
            > above is faulty. Youv'e declared a stack where each element is 3
            > strings. This is fine in principle, but probaly what you should do is
            > declare a struct that defines the stack elements, then declare the
            > stack as a stack of those things, like this:[/color]

            Right, that's what I ended up doing.

            What I'm curious about is whether I can *directly* define a stack<...>
            of an array or not. My compiler decidedly didn't like it.

            [color=blue]
            >
            > struct STRINGS
            > {
            > string m_Strings[3];
            > }; // STRINGS
            >
            > int main()
            > {
            > std::stack<STRI NGS> stk;
            > return 0;
            > }
            >
            > </dib>
            > John Dibling
            > Witty banter omitted for your protection[/color]

            Comment

            • Victor Bazarov

              #7
              Re: containers of arrays?

              "Stephen J. Fromm" <stephen.fromm@ verizon.net> wrote...[color=blue]
              > "Victor Bazarov" <v.Abazarov@att Abi.com> wrote in message[/color]
              news:<vidcq25k0 vspdb@corp.supe rnews.com>...[color=blue][color=green]
              > > "Stephen J. Fromm" <stephen.fromm@ verizon.net> wrote...[color=darkred]
              > > > I take it I cannot form a container of an array type? For example,
              > > > stack<string[3]> parentStack;[/color]
              > >
              > > Yes.[/color]
              >
              > Victor,
              >
              > Yes, I can form, or yes, I cannot form?[/color]

              Cannot. Arrays do not satisfy the requirements for contained
              items: CopyContstructi ble and Assignable.

              Victor


              Comment

              • Rolf Magnus

                #8
                Re: containers of arrays?

                Stephen J. Fromm wrote:
                [color=blue]
                > What I'm curious about is whether I can *directly* define a stack<...>
                > of an array or not.[/color]

                Not.

                Comment

                Working...