trouble with structs

Discussion in 'C++' started by Naive Programmer, Jun 23, 2008.

  1. 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!
     
    Naive Programmer, Jun 23, 2008
    #1
    1. Advertising

  2. Naive Programmer

    ManicQin Guest

    On Jun 23, 8:52 am, Naive Programmer
    <> 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, Jun 23, 2008
    #2
    1. Advertising

  3. Naive Programmer

    Eric Pruneau Guest

    "Naive Programmer" <> a écrit dans le
    message de news:
    ...
    > 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...
     
    Eric Pruneau, Jun 23, 2008
    #3
  4. 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 <> wrote:
    > On Jun 23, 8:52 am, Naive Programmer
    >
    >
    >
    > <> 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.
     
    Naive Programmer, Jun 23, 2008
    #4
  5. Naive Programmer

    ManicQin Guest

    On Jun 23, 11:09 am, Naive Programmer
    <> 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 <> wrote:
    >
    >
    >
    > > On Jun 23, 8:52 am, Naive Programmer

    >
    > > <> 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
     
    ManicQin, Jun 23, 2008
    #5
  6. Naive Programmer

    Ramkey Guest

    On Jun 23, 5:52 am, Naive Programmer
    <> 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.
     
    Ramkey, Jun 23, 2008
    #6
  7. Naive Programmer

    asterisc Guest

    On Jun 23, 12:00 pm, Ramkey <> wrote:
    > On Jun 23, 5:52 am, Naive Programmer
    >
    >
    >
    > <> 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.
     
    asterisc, Jun 23, 2008
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Patricia  Van Hise

    structs with fields that are structs

    Patricia Van Hise, Apr 5, 2004, in forum: C Programming
    Replies:
    5
    Views:
    641
    Al Bowers
    Apr 5, 2004
  2. Chris Hauxwell

    const structs in other structs

    Chris Hauxwell, Apr 23, 2004, in forum: C Programming
    Replies:
    6
    Views:
    560
    Chris Hauxwell
    Apr 27, 2004
  3. Paminu
    Replies:
    5
    Views:
    645
    Eric Sosman
    Oct 11, 2005
  4. Daniel Rudy
    Replies:
    15
    Views:
    1,405
    Keith Thompson
    Apr 10, 2006
  5. Tuan  Bui
    Replies:
    14
    Views:
    476
    it_says_BALLS_on_your forehead
    Jul 29, 2005
Loading...

Share This Page