Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   trouble with structs (http://www.velocityreviews.com/forums/t621724-trouble-with-structs.html)

Naive Programmer 06-23-2008 12:52 AM

trouble with structs
 
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!

ManicQin 06-23-2008 01:16 AM

Re: trouble with structs
 
On Jun 23, 8:52*am, Naive Programmer
<priedi...@lookaheaddecisions.com> wrote:
> 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.

Eric Pruneau 06-23-2008 01:43 AM

Re: trouble with structs
 

"Naive Programmer" <prieditis@lookaheaddecisions.com> a écrit dans le
message de news:
c4d69bb5-64f4-4515-858e-18e7dba47109...oglegroups.com...
> 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...



Naive Programmer 06-23-2008 03:09 AM

Re: trouble with structs
 
Here's the error I get:

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

On Jun 22, 6:16 pm, ManicQin <Manic...@gmail.com> wrote:
> On Jun 23, 8:52 am, Naive Programmer
>
>
>
> <priedi...@lookaheaddecisions.com> wrote:
> > 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.





ManicQin 06-23-2008 07:49 AM

Re: trouble with structs
 
On Jun 23, 11:09*am, Naive Programmer
<priedi...@lookaheaddecisions.com> wrote:
> Here's the error I get:
>
> holding[0].list[0].color * * * *CXX0025: Error: operator needs class/struct/
> union
>
> On Jun 22, 6:16 pm, ManicQin <Manic...@gmail.com> wrote:
>
>
>
> > On Jun 23, 8:52 am, Naive Programmer

>
> > <priedi...@lookaheaddecisions.com> wrote:
> > > 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

Ramkey 06-23-2008 09:00 AM

Re: trouble with structs
 
On Jun 23, 5:52 am, Naive Programmer
<priedi...@lookaheaddecisions.com> wrote:
> 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.

asterisc 06-23-2008 09:31 AM

Re: trouble with structs
 
On Jun 23, 12:00*pm, Ramkey <Ramakrishnaprasa...@gmail.com> wrote:
> On Jun 23, 5:52 am, Naive Programmer
>
>
>
> <priedi...@lookaheaddecisions.com> wrote:
> > 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.


All times are GMT. The time now is 01:40 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.