473,387 Members | 1,516 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

containers of arrays?

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

TIA,

sjfromm
Jul 19 '05 #1
7 1625
"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
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
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
"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
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
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: George Sakkis | last post by:
Hi all, I find the string representation behaviour of builtin containers (tuples,lists,dicts) unintuitive in that they don't call recursively str() on their contents (e.g. as in Java) : ...
2
by: bartek | last post by:
Hello, It is not possible to assign values to, say, a vector<float> due to the fact that arrays are not assignable. Theoretically there's a simple workaround which involves wrapping the array...
5
by: slurper | last post by:
when i do this vector < vector<int> > p; later in the code i do things like this: vector<int> x,y,z; p.push_back(x); p.push_back(y); p.push_back(z);
8
by: Ross A. Finlayson | last post by:
I'm trying to write some C code, but I want to use C++'s std::vector. Indeed, if the code is compiled as C++, I want the container to actually be std::vector, in this case of a collection of value...
3
by: Andrew Ward | last post by:
Hi, A third-party container library I use implements its containers using copy-on-write semantics, making it efficient to return an instance of the container by value from a function. For...
18
by: Simon | last post by:
Hi, I understand what one the differences between std::vector, std::deque and std::list is, the std::vector can have data inserted/deleted at the end. The std::deque can have data...
5
by: paul | last post by:
Hi, i want to know if this is better to split a tablespace into several containers while the database are on san disk. And how can i configure optimally the values for prefetch and extend ? thx
11
by: jimxoch | last post by:
Hi list, Most STL containers are storing their data on the heap. (although some std::string implementations are notable exceptions) Of course, using the heap as storage increases flexibility and...
14
by: Remo D. | last post by:
I've read with much interest the threads on how to create data containers in C. I started thinking if simpler ADT (other than the proposed List) could be used as a starting point. What about...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.