Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #8506 > unrolled thread
| Started by | mrc2323@cox.net (Mike Copeland) |
|---|---|
| First post | 2011-08-06 11:33 -0700 |
| Last post | 2011-08-07 13:16 -0400 |
| Articles | 9 — 5 participants |
Back to article view | Back to comp.lang.c++
Setting Structure Defaults mrc2323@cox.net (Mike Copeland) - 2011-08-06 11:33 -0700
Re: Setting Structure Defaults Victor Bazarov <v.bazarov@comcast.invalid> - 2011-08-06 15:31 -0400
Re: Setting Structure Defaults mrc2323@cox.net (Mike Copeland) - 2011-08-06 22:55 -0700
Re: Setting Structure Defaults "Balog Pal" <pasa@lib.hu> - 2011-08-07 08:46 +0200
Re: Setting Structure Defaults "Bo Persson" <bop@gmb.dk> - 2011-08-07 12:30 +0200
Re: Setting Structure Defaults mrc2323@cox.net (Mike Copeland) - 2011-08-07 09:17 -0700
Re: Setting Structure Defaults Geoff <geoff@invalid.invalid> - 2011-08-07 10:00 -0700
Re: Setting Structure Defaults Victor Bazarov <v.bazarov@comcast.invalid> - 2011-08-07 13:17 -0400
Re: Setting Structure Defaults Victor Bazarov <v.bazarov@comcast.invalid> - 2011-08-07 13:16 -0400
| From | mrc2323@cox.net (Mike Copeland) |
|---|---|
| Date | 2011-08-06 11:33 -0700 |
| Subject | Setting Structure Defaults |
| Message-ID | <MPG.28a736d5dcd815509896c4@news.eternal-september.org> |
I'm trying to create a structure and populate it with default values.
Below is my attempt, but it fails (badly) to compile. What did I do
wrong here? How might I fix this? TIA
#define ERLIMIT 5
struct ERMENU
{
string title;
short xAxis, yAxis;
short titleLen, dataLen;
short linkPrior, linkNext;
short option;
WORD dispAttr;
short erHead, erTail, erCurrent;
} erMenu[ERLIMIT] =
{
{"category1", 2, 4, 9, 1, 0, 0, 0, LONORM, 0, 0, 0},
{"category2", 2, 5, 9, 1, 0, 0, 0, LONORM, 0, 0, 0},
{"category3", 2, 6, 9, 1, 0, 0, 0, LONORM, 0, 0, 0},
{"category4", 2, 7, 9, 1, 0, 0, 0, LONORM, 0, 0, 0},
{"category5", 2, 8, 9, 1, 0, 0, 0, LONORM, 0, 0, 0}
};
[toc] | [next] | [standalone]
| From | Victor Bazarov <v.bazarov@comcast.invalid> |
|---|---|
| Date | 2011-08-06 15:31 -0400 |
| Message-ID | <j1k4rr$ujc$1@dont-email.me> |
| In reply to | #8506 |
On 8/6/2011 2:33 PM, Mike Copeland wrote:
> I'm trying to create a structure and populate it with default values.
> Below is my attempt, but it fails (badly) to compile. What did I do
> wrong here? How might I fix this? TIA
>
> #define ERLIMIT 5
> struct ERMENU
> {
> string title;
> short xAxis, yAxis;
> short titleLen, dataLen;
> short linkPrior, linkNext;
> short option;
> WORD dispAttr;
> short erHead, erTail, erCurrent;
> } erMenu[ERLIMIT] =
> {
> {"category1", 2, 4, 9, 1, 0, 0, 0, LONORM, 0, 0, 0},
> {"category2", 2, 5, 9, 1, 0, 0, 0, LONORM, 0, 0, 0},
> {"category3", 2, 6, 9, 1, 0, 0, 0, LONORM, 0, 0, 0},
> {"category4", 2, 7, 9, 1, 0, 0, 0, LONORM, 0, 0, 0},
> {"category5", 2, 8, 9, 1, 0, 0, 0, LONORM, 0, 0, 0}
> };
>
This is covered by FAQ 5.8. Please read the FAQ before posting.
V
--
I do not respond to top-posted replies, please don't ask
[toc] | [prev] | [next] | [standalone]
| From | mrc2323@cox.net (Mike Copeland) |
|---|---|
| Date | 2011-08-06 22:55 -0700 |
| Message-ID | <MPG.28a7d6d1917d30d9896c5@news.eternal-september.org> |
| In reply to | #8510 |
In article <j1k4rr$ujc$1@dont-email.me>, v.bazarov@comcast.invalid
says...
> On 8/6/2011 2:33 PM, Mike Copeland wrote:
> > I'm trying to create a structure and populate it with default values.
> > Below is my attempt, but it fails (badly) to compile. What did I do
> > wrong here? How might I fix this? TIA
> >
> > #define ERLIMIT 5
> > struct ERMENU
> > {
> > string title;
> > short xAxis, yAxis;
> > short titleLen, dataLen;
> > short linkPrior, linkNext;
> > short option;
> > WORD dispAttr;
> > short erHead, erTail, erCurrent;
> > } erMenu[ERLIMIT] =
> > {
> > {"category1", 2, 4, 9, 1, 0, 0, 0, LONORM, 0, 0, 0},
> > {"category2", 2, 5, 9, 1, 0, 0, 0, LONORM, 0, 0, 0},
> > {"category3", 2, 6, 9, 1, 0, 0, 0, LONORM, 0, 0, 0},
> > {"category4", 2, 7, 9, 1, 0, 0, 0, LONORM, 0, 0, 0},
> > {"category5", 2, 8, 9, 1, 0, 0, 0, LONORM, 0, 0, 0}
> > };
> >
> This is covered by FAQ 5.8. Please read the FAQ before posting.
I don't understand. The FAQ reference (5.8) has nothing to do with
my query here, and examining the FAQ doesn't lead me to a resolution of
my problem. I'm seeking an understanding of how to initialize a
structure element that is declared as basic::string, which is the root
cause of my compile errors.
I can't find anything in the FAQ that deals with this. 8<{{
[toc] | [prev] | [next] | [standalone]
| From | "Balog Pal" <pasa@lib.hu> |
|---|---|
| Date | 2011-08-07 08:46 +0200 |
| Message-ID | <j1lcd5$ckh$1@news.ett.com.ua> |
| In reply to | #8529 |
"Mike Copeland" <mrc2323@cox.net> az alábbiakat írta a következő
hírüzenetben: MPG.28a7d6d1917d30d9896c5@news.eternal-september.org...
> In article <j1k4rr$ujc$1@dont-email.me>, v.bazarov@comcast.invalid
> says...
>> On 8/6/2011 2:33 PM, Mike Copeland wrote:
>> > I'm trying to create a structure and populate it with default
>> > values.
>> > Below is my attempt, but it fails (badly) to compile. What did I do
>> > wrong here? How might I fix this? TIA
>> >
>> > #define ERLIMIT 5
>> > struct ERMENU
>> > {
>> > string title;
>> > short xAxis, yAxis;
>> > short titleLen, dataLen;
>> > short linkPrior, linkNext;
>> > short option;
>> > WORD dispAttr;
>> > short erHead, erTail, erCurrent;
>> > } erMenu[ERLIMIT] =
>> > {
>> > {"category1", 2, 4, 9, 1, 0, 0, 0, LONORM, 0, 0, 0},
>> > {"category2", 2, 5, 9, 1, 0, 0, 0, LONORM, 0, 0, 0},
>> > {"category3", 2, 6, 9, 1, 0, 0, 0, LONORM, 0, 0, 0},
>> > {"category4", 2, 7, 9, 1, 0, 0, 0, LONORM, 0, 0, 0},
>> > {"category5", 2, 8, 9, 1, 0, 0, 0, LONORM, 0, 0, 0}
>> > };
>> >
>> This is covered by FAQ 5.8. Please read the FAQ before posting.
>
> I don't understand. The FAQ reference (5.8) has nothing to do with
> my query here, and examining the FAQ doesn't lead me to a resolution of
> my problem. I'm seeking an understanding of how to initialize a
> structure element that is declared as basic::string, which is the root
> cause of my compile errors.
> I can't find anything in the FAQ that deals with this.
I bet there is a section about how-to-post-code, that you clearly did not
follow. :-(
Anyway,
#include <string>
struct S
{
// const char * s;
std::string s;
int i;
} o[2] =
{
{ "a", 1 },
{ "b", 2 },
};
complies fine in cameau, so the best bet is that you messed up somewhere
else.
And your code only get complaints on WORD and LONROM too.
[toc] | [prev] | [next] | [standalone]
| From | "Bo Persson" <bop@gmb.dk> |
|---|---|
| Date | 2011-08-07 12:30 +0200 |
| Message-ID | <9a77qdFn1oU1@mid.individual.net> |
| In reply to | #8529 |
Mike Copeland wrote:
> In article <j1k4rr$ujc$1@dont-email.me>, v.bazarov@comcast.invalid
> says...
>> On 8/6/2011 2:33 PM, Mike Copeland wrote:
>>> I'm trying to create a structure and populate it with default
>>> values. Below is my attempt, but it fails (badly) to compile.
>>> What did I do wrong here? How might I fix this? TIA
>>>
>>> #define ERLIMIT 5
>>> struct ERMENU
>>> {
>>> string title;
>>> short xAxis, yAxis;
>>> short titleLen, dataLen;
>>> short linkPrior, linkNext;
>>> short option;
>>> WORD dispAttr;
>>> short erHead, erTail, erCurrent;
>>> } erMenu[ERLIMIT] =
>>> {
>>> {"category1", 2, 4, 9, 1, 0, 0, 0, LONORM, 0, 0, 0},
>>> {"category2", 2, 5, 9, 1, 0, 0, 0, LONORM, 0, 0, 0},
>>> {"category3", 2, 6, 9, 1, 0, 0, 0, LONORM, 0, 0, 0},
>>> {"category4", 2, 7, 9, 1, 0, 0, 0, LONORM, 0, 0, 0},
>>> {"category5", 2, 8, 9, 1, 0, 0, 0, LONORM, 0, 0, 0}
>>> };
>>>
>> This is covered by FAQ 5.8. Please read the FAQ before posting.
>
> I don't understand. The FAQ reference (5.8) has nothing to do
> with my query here, and examining the FAQ doesn't lead me to a
> resolution of my problem. I'm seeking an understanding of how to
> initialize a structure element that is declared as basic::string,
> which is the root cause of my compile errors.
> I can't find anything in the FAQ that deals with this. 8<{{
It's a meta reference - One of the points of 5.8 is that you should
tell us WHAT message you get from the compiler.
And you just did!
Bo Persson
[toc] | [prev] | [next] | [standalone]
| From | mrc2323@cox.net (Mike Copeland) |
|---|---|
| Date | 2011-08-07 09:17 -0700 |
| Message-ID | <MPG.28a8687f51a49f469896c6@news.eternal-september.org> |
| In reply to | #8533 |
In article <9a77qdFn1oU1@mid.individual.net>, bop@gmb.dk says...
> Mike Copeland wrote:
> > In article <j1k4rr$ujc$1@dont-email.me>, v.bazarov@comcast.invalid
> > says...
> >> On 8/6/2011 2:33 PM, Mike Copeland wrote:
> >>> I'm trying to create a structure and populate it with default
> >>> values. Below is my attempt, but it fails (badly) to compile.
> >>> What did I do wrong here? How might I fix this? TIA
> >>>
> >>> #define ERLIMIT 5
> >>> struct ERMENU
> >>> {
> >>> string title;
> >>> short xAxis, yAxis;
> >>> short titleLen, dataLen;
> >>> short linkPrior, linkNext;
> >>> short option;
> >>> WORD dispAttr;
> >>> short erHead, erTail, erCurrent;
> >>> } erMenu[ERLIMIT] =
> >>> {
> >>> {"category1", 2, 4, 9, 1, 0, 0, 0, LONORM, 0, 0, 0},
> >>> {"category2", 2, 5, 9, 1, 0, 0, 0, LONORM, 0, 0, 0},
> >>> {"category3", 2, 6, 9, 1, 0, 0, 0, LONORM, 0, 0, 0},
> >>> {"category4", 2, 7, 9, 1, 0, 0, 0, LONORM, 0, 0, 0},
> >>> {"category5", 2, 8, 9, 1, 0, 0, 0, LONORM, 0, 0, 0}
> >>> };
> >>>
> >> This is covered by FAQ 5.8. Please read the FAQ before posting.
> >
> > I don't understand. The FAQ reference (5.8) has nothing to do
> > with my query here, and examining the FAQ doesn't lead me to a
> > resolution of my problem. I'm seeking an understanding of how to
> > initialize a structure element that is declared as basic::string,
> > which is the root cause of my compile errors.
> > I can't find anything in the FAQ that deals with this. 8<{{
>
> It's a meta reference - One of the points of 5.8 is that you should
> tell us WHAT message you get from the compiler.
>
> And you just did!
My apologies. I received a maximum number of C2440 errors with this
code (VS6.0 on Windows XP), but I thought posting a compiler/system-
specific error was/is greatly frowned upon here. Also, regarding the
FAQ 5.8, since I couldn't compile this code (which was cut & pasted from
my program), I couldn't post working code. 8<{{
I was only trying to find out how to write the string-initialize
code, and I thought my query was complete and appropriate. <sigh...>
[toc] | [prev] | [next] | [standalone]
| From | Geoff <geoff@invalid.invalid> |
|---|---|
| Date | 2011-08-07 10:00 -0700 |
| Message-ID | <m1ht37p513ttlgfuind0vo1m2trc423cln@4ax.com> |
| In reply to | #8539 |
#include <windows.h> /* for definition of WORD */
#define LONORM 1 /* application specific constant? */
#define ERLIMIT 5
struct ERMENU
{
std::string title; /* changed from string to std::string */
short xAxis, yAxis;
short titleLen, dataLen;
short linkPrior, linkNext;
short option;
WORD dispAttr;
short erHead, erTail, erCurrent;
} erMenu[ERLIMIT] =
{
{"category1", 2, 4, 9, 1, 0, 0, 0, LONORM, 0, 0, 0},
{"category2", 2, 5, 9, 1, 0, 0, 0, LONORM, 0, 0, 0},
{"category3", 2, 6, 9, 1, 0, 0, 0, LONORM, 0, 0, 0},
{"category4", 2, 7, 9, 1, 0, 0, 0, LONORM, 0, 0, 0},
{"category5", 2, 8, 9, 1, 0, 0, 0, LONORM, 0, 0, 0}
};
Works fine in VS2010.
[toc] | [prev] | [next] | [standalone]
| From | Victor Bazarov <v.bazarov@comcast.invalid> |
|---|---|
| Date | 2011-08-07 13:17 -0400 |
| Message-ID | <j1mhat$qd3$2@dont-email.me> |
| In reply to | #8540 |
On 8/7/2011 1:00 PM, Geoff wrote:
> #include<windows.h> /* for definition of WORD */
> #define LONORM 1 /* application specific constant? */
>
> #define ERLIMIT 5
>
> struct ERMENU
> {
> std::string title; /* changed from string to std::string */
> short xAxis, yAxis;
> short titleLen, dataLen;
> short linkPrior, linkNext;
> short option;
> WORD dispAttr;
> short erHead, erTail, erCurrent;
> } erMenu[ERLIMIT] =
> {
> {"category1", 2, 4, 9, 1, 0, 0, 0, LONORM, 0, 0, 0},
> {"category2", 2, 5, 9, 1, 0, 0, 0, LONORM, 0, 0, 0},
> {"category3", 2, 6, 9, 1, 0, 0, 0, LONORM, 0, 0, 0},
> {"category4", 2, 7, 9, 1, 0, 0, 0, LONORM, 0, 0, 0},
> {"category5", 2, 8, 9, 1, 0, 0, 0, LONORM, 0, 0, 0}
> };
>
> Works fine in VS2010.
No shit. Now try it with VS v6.0...
V
--
I do not respond to top-posted replies, please don't ask
[toc] | [prev] | [next] | [standalone]
| From | Victor Bazarov <v.bazarov@comcast.invalid> |
|---|---|
| Date | 2011-08-07 13:16 -0400 |
| Message-ID | <j1mh9e$qd3$1@dont-email.me> |
| In reply to | #8539 |
On 8/7/2011 12:17 PM, Mike Copeland wrote:
> [..] I received a maximum number of C2440 errors with this
> code (VS6.0 on Windows XP), but I thought posting a compiler/system-
> specific error was/is greatly frowned upon here. Also, regarding the
> FAQ 5.8, since I couldn't compile this code (which was cut& pasted from
> my program), I couldn't post working code. 8<{{
> I was only trying to find out how to write the string-initialize
> code, and I thought my query was complete and appropriate.<sigh...>
VS6.0 is not Standard compliant by any stretch of the imagination.
Nobody in their right mind uses that compiler any longer. Please find a
better compiler and port to it (unless you really *have* to stick with
that fossil due to some 3rd party dependency, or whatever). AFA
std::string initialization from a string literal (double-quoted stuff in
your program), you will have to use this form:
struct BLAH { std::string s; } blah[] = { std::string("blah") };
because the compiler is so bad that it can't understand that it needs to
use a specific constructor.
V
--
I do not respond to top-posted replies, please don't ask
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.c++
csiph-web