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

containers of arrays?

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

TIA,

sjfromm
Jul 19 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
"Stephen J. Fromm" <st***********@verizon.net> wrote...
I take it I cannot form a container of an array type? For example,
stack<string[3]> parentStack;


Yes.
Jul 19 '05 #2

P: n/a
On 29 Jul 2003 10:18:57 -0700, st***********@verizon.net (Stephen J.
Fromm) wrote:
I take it I cannot form a container of an array type? For example,
stack<string[3]> parentStack;

TIA,

sjfromm


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<STRINGS> stk;
return 0;
}

</dib>
John Dibling
Witty banter omitted for your protection
Jul 19 '05 #3

P: n/a
John Dibling wrote:
On 29 Jul 2003 10:18:57 -0700, st***********@verizon.net (Stephen J.
Fromm) wrote:
I take it I cannot form a container of an array type? For example,
stack<string[3]> parentStack;

TIA,

sjfromm
You can have containers of arrays,


No, you can't.
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,
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.
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<STRINGS> stk;
return 0;
}


That would work.

Jul 19 '05 #4

P: n/a
"Victor Bazarov" <v.********@attAbi.com> wrote in message news:<vi************@corp.supernews.com>...
"Stephen J. Fromm" <st***********@verizon.net> wrote...
I take it I cannot form a container of an array type? For example,
stack<string[3]> parentStack;


Yes.


Victor,

Yes, I can form, or yes, I cannot form?
Jul 19 '05 #5

P: n/a
John Dibling <dib@substitute_my_full_last_name_here.com> wrote in message news:<n3********************************@4ax.com>. ..
On 29 Jul 2003 10:18:57 -0700, st***********@verizon.net (Stephen J.
Fromm) wrote:
Thanks for your reply.
I take it I cannot form a container of an array type? For example,
stack<string[3]> parentStack;

TIA,

sjfromm


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:


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.


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

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

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

Jul 19 '05 #6

P: n/a
"Stephen J. Fromm" <st***********@verizon.net> wrote...
"Victor Bazarov" <v.********@attAbi.com> wrote in message

news:<vi************@corp.supernews.com>...
"Stephen J. Fromm" <st***********@verizon.net> wrote...
I take it I cannot form a container of an array type? For example,
stack<string[3]> parentStack;


Yes.


Victor,

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


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

Victor
Jul 19 '05 #7

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


Not.

Jul 19 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.