trouble with structs

N

Naive Programmer

Hi,
I need some simple help. First, I should apologize: I am a total
programming fool in C++ and am trying to get some basic structs
working before I attempt classes. I can't seem to get the references
to those structs working properly and need help.

Suppose I have:
struct info
{
int color;
int count;
};

struct queue{
int front;
info list[15];
};


struct queue holding[20];

First, did I get the syntax right above?

Second, it this the right syntax for setting to 5 the color of list
element 0 of holding element 0?

holding[0].list[0].color = 5

Both of these pass through the compiler fine But
holding[0].list[0].color doesn't seem to appear properly on my VC++
variables list when I run in debug mode. It doesn't display anything
within list, when I think it should display color and count. What's
wrong? Thanks!
 
M

ManicQin

Hi,
I need some simple help. First, I should apologize: I am a total
programming fool in C++ and am trying to get some basic structs
working before I attempt classes. I can't seem to get the references
to those structs working properly and need help.

Suppose I have:
struct info
{
        int color;
        int count;

};

struct queue{
        int front;
        info list[15];

};

struct queue holding[20];

First, did I get the syntax right above?

Second, it this the right syntax for  setting to 5 the color of list
element 0 of holding element 0?

holding[0].list[0].color = 5

Both of these pass through the compiler fine  But
holding[0].list[0].color doesn't seem to appear properly on my VC++
variables list when I run in debug mode. It doesn't display anything
within list, when I think it should display color and count.  What's
wrong?  Thanks!

It is a bit Off Topic but If you send me a print screen to my email
I'll see if I understand you better.

Maybe you are in a wrong scope.
 
E

Eric Pruneau

"Naive Programmer" <[email protected]> a écrit dans le
message de
(e-mail address removed)...
Hi,
I need some simple help. First, I should apologize: I am a total
programming fool in C++ and am trying to get some basic structs
working before I attempt classes. I can't seem to get the references
to those structs working properly and need help.

First, the ONLY difference between a struct and a class is that every member
of a struct are public by default while member of a class are private by
default. So learning how struct works is learning how class works.

Suppose I have:
struct info
{
int color;
int count;
};

you could also write
class info
{
public:
int color;
int count;
}

struct queue{
int front;
info list[15];
};


struct queue holding[20];

First, did I get the syntax right above?

struct queue holding[20];
is valid but it is C style programming. You should drop the struct like this

queue holding[20];
Second, it this the right syntax for setting to 5 the color of list
element 0 of holding element 0?

holding[0].list[0].color = 5
yes


Both of these pass through the compiler fine But
holding[0].list[0].color doesn't seem to appear properly on my VC++
variables list when I run in debug mode. It doesn't display anything
within list, when I think it should display color and count. What's
wrong? Thanks!

No idea cause it should work...
 
N

Naive Programmer

Here's the error I get:

holding[0].list[0].color CXX0025: Error: operator needs class/struct/
union

Hi,
I need some simple help. First, I should apologize: I am a total
programming fool in C++ and am trying to get some basic structs
working before I attempt classes. I can't seem to get the references
to those structs working properly and need help.
Suppose I have:
struct info
{
int color;
int count;

struct queue{
int front;
info list[15];

struct queue holding[20];
First, did I get the syntax right above?
Second, it this the right syntax for setting to 5 the color of list
element 0 of holding element 0?
holding[0].list[0].color = 5
Both of these pass through the compiler fine But
holding[0].list[0].color doesn't seem to appear properly on my VC++
variables list when I run in debug mode. It doesn't display anything
within list, when I think it should display color and count. What's
wrong? Thanks!

It is a bit Off Topic but If you send me a print screen to my email
I'll see if I understand you better.

Maybe you are in a wrong scope.
 
M

ManicQin

Here's the error I get:

holding[0].list[0].color        CXX0025: Error: operator needs class/struct/
union

Hi,
I need some simple help. First, I should apologize: I am a total
programming fool in C++ and am trying to get some basic structs
working before I attempt classes. I can't seem to get the references
to those structs working properly and need help.
Suppose I have:
struct info
{
        int color;
        int count;
};
struct queue{
        int front;
        info list[15];
};
struct queue holding[20];
First, did I get the syntax right above?
Second, it this the right syntax for  setting to 5 the color of list
element 0 of holding element 0?
holding[0].list[0].color = 5
Both of these pass through the compiler fine  But
holding[0].list[0].color doesn't seem to appear properly on my VC++
variables list when I run in debug mode. It doesn't display anything
within list, when I think it should display color and count.  What's
wrong?  Thanks!
It is a bit Off Topic but If you send me a print screen to my email
I'll see if I understand you better.
Maybe you are in a wrong scope.- Hide quoted text -

- Show quoted text -

Weird... Send me a screen shot
 
R

Ramkey

Hi,
I need some simple help. First, I should apologize: I am a total
programming fool in C++ and am trying to get some basic structs
working before I attempt classes. I can't seem to get the references
to those structs working properly and need help.

Suppose I have:
struct info
{
int color;
int count;

};

struct queue{
int front;
info list[15];

};

struct queue holding[20];

First, did I get the syntax right above?

Second, it this the right syntax for setting to 5 the color of list
element 0 of holding element 0?

holding[0].list[0].color = 5

Both of these pass through the compiler fine But
holding[0].list[0].color doesn't seem to appear properly on my VC++
variables list when I run in debug mode. It doesn't display anything
within list, when I think it should display color and count. What's
wrong? Thanks!

Change
struct queue{
int front;
info list[15];

};

to
struct queue{
int front;
struct info list[15];
};

Because info needs to be of a type.Tell me if it worked.I too am
curious about the output.
 
A

asterisc

Hi,
I need some simple help. First, I should apologize: I am a total
programming fool in C++ and am trying to get some basic structs
working before I attempt classes. I can't seem to get the references
to those structs working properly and need help.
Suppose I have:
struct info
{
        int color;
        int count;

struct queue{
        int front;
        info list[15];

struct queue holding[20];
First, did I get the syntax right above?
Second, it this the right syntax for  setting to 5 the color of list
element 0 of holding element 0?
holding[0].list[0].color = 5
Both of these pass through the compiler fine  But
holding[0].list[0].color doesn't seem to appear properly on my VC++
variables list when I run in debug mode. It doesn't display anything
within list, when I think it should display color and count.  What's
wrong?  Thanks!

Change
struct queue{
        int front;
        info list[15];

};

to
struct queue{
        int front;
        struct info list[15];

};

Because info needs to be of a type.Tell me if it worked.I too am
curious about the output.

In C++, a struct defines a new type, exactly as class does.
However, if he uses a C compiler, probably that can be the problem.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top