|
From: Naive Programmer on 22 Jun 2008 18:58 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, Is this the right syntax for setting to 5 the color of list element 0 of holding element 0? Both of these pass through the compiler fine. holding[0].list[0].color = 5 If so, holding[0].list[0].color doesn't seem to appear properly on my VC++ variables list when I run in debug mode. What's wrong. Thanks! -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Jyoti Sharma on 23 Jun 2008 05:47 On Mon, 23 Jun 2008 15:28:00 +0530, Naive Programmer <prieditis(a)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, Is this the right > syntax for setting to 5 the color of list element 0 of holding > element 0? Both of these pass through the compiler fine. > > holding[0].list[0].color = 5 > > If so, holding[0].list[0].color doesn't seem to appear properly on my > VC++ variables list when I run in debug mode. What's wrong. Thanks! > In C you would need to say struct info list[15]; it is alright in C++. holding[0].list[0].color does hold 5. I checked with Borland compiler. Maybe you are checking the value before it is actually assigned or maybe your debug window is not updating the value immediately. Why don't you give a try to simply print the value? -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Thomas Maeder on 23 Jun 2008 05:47 Naive Programmer <prieditis(a)lookaheaddecisions.com> writes: > 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 don't see what part of that would require an apology. Everybody is a fool sometimes, and every C++ programmer is or was a beginner. > 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]; "struct" is superfluous on this line if this is C++ code. > First, did I get the syntax right above. Second, Is this the right > syntax for setting to 5 the color of list element 0 of holding > element 0? Both of these pass through the compiler fine. > > holding[0].list[0].color = 5 Yes, that's correct. The name list is a bit unfortunate IMHO, because that's also the name of a Standard C++ Library container template. -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Martin Bonner on 23 Jun 2008 05:43 On Jun 23, 10:58 am, Naive Programmer <priedi...(a)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. Looks OK to me. > Second, Is this the right > syntax for setting to 5 the color of list element 0 of holding > element 0? Both of these pass through the compiler fine. > > holding[0].list[0].color = 5 Also good. > > If so, holding[0].list[0].color doesn't seem to appear properly on my > VC++ variables list when I run in debug mode. What's wrong. Thanks! Don't know. How does it appear? What do you expect to appear? Having said that, the VC++ variables list is (very) platform specific. If your problem is with the debugger, you might be better off asking on a platform specific newsgroup. (Even if you do, you'll have to tell them what you see and what you expect to see). On the other hand, your problem is quite likely to be a platform specific manifestation of a general problem. Can you post a complete (short) example of the code which has problems? (Warning: if you create a command line program with VC, it will try to give it "int _tmain( int argc, TCHAR* argv[])" or something similar. Turn that into proper "int main(int argc, char* argv[] )" please.) Finally: You would probably be better off getting either Accelerated C+ +, or "You can do it!" which teach C++ from the ground up, and don't use advanced features like C-style arrays until you have got the hang of simpler stuff like vector. (The problem is that most people who write books, teach it the way they learnt it - as a conversion from C. This is not a good way to learn C++ ab-initio; they are different languages with different idioms.) -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: tim todd on 23 Jun 2008 05:48 > struct info > { > int color; > int count; > }; > > struct queue{ > int front; > info list[15]; > }; > struct queue holding[20]; > holding[0].list[0].color = 5 Seems OK, Other than the lack of initialization. My debugger doesn't like the multi-level structs. But do this: info sInfo = holding[0].list[0]; and look at sInfo. t. -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
|
Pages: 1 Prev: How is common_type (N2615) supposed to work? Next: Template and Inheritance |