|
struct |
Albin Engström
Member #8,110
December 2006
|
mm, having a little problem here: making an interface for 'a program' and i am using dynamic values to change the color of the text. for some reason i can use global values but not those stored in structures... this is the messege i get when compiling: "expected primary-expression before '.' token".. NOT WORKING CODE PIECE: WORKING CODE PIECE: Why god, why?! (i have a feeling i'm missing something very .. basic..) |
miran
Member #2,407
June 2002
|
Post more information. -- |
HoHo
Member #4,534
April 2004
|
Are any of those structures or parts of the structure allocated dynamically? If yes then use "->" instead of "." __________ |
Marco Radaelli
Member #3,028
December 2002
|
Well, apart from the missing bracket What's textcol? A pointer to function?
|
miran
Member #2,407
June 2002
|
@Marco: textcol1 is obviously the R component of the colour. So you're wrong. -- |
Albin Engström
Member #8,110
December 2006
|
allocated dynamically??? the missing braclet wasn't there in the original code piece .. more information... like? makecol1: int makecol1; |
miran
Member #2,407
June 2002
|
More information like how and where those structs are declared and how the actual objects are created. -- |
Albin Engström
Member #8,110
December 2006
|
ouch.. this is going to be painful.. i declare my structures like this: struct game { struct graphics { struct _interface { int textcol1; ... }_interface; }graphics; }game;
- - he? |
miran
Member #2,407
June 2002
|
And which language is this in? C or C++? Is this code in a header? -- |
Albin Engström
Member #8,110
December 2006
|
C++ - Not a header. (i put everything into the same file..) - - |
miran
Member #2,407
June 2002
|
The following code compiles without problems when I put it in a file called test.cpp:
Can you write a similar example that doesn't compile? -- |
tobing
Member #5,213
November 2004
|
In your code, game, graphics and _interface are structures, not instances. So you can't write "game.graphics._interface.textcol1". What you CAN do is: have an instance of type game::graphics::_interface, say ifc, then use ifc.textcol1. Code: game::graphics::_interface ifc; ifc.textcol1 = 45; Edit: Oops, I didn't see the names following the struct definitions. So that means then that the structure names are also at the same time names for the corresponding members. Urgs. I'm not used to code like this... |
Albin Engström
Member #8,110
December 2006
|
The following code.. works.
did some more research and turns out that i have no trouble doing this:
This Code Should not work.. (i didn't compile it due to this incredible crappy computer here in school (and the others).. takes abuot 4min compiling this shit - -). "not used to this kind of code..." it means it sucks right ^^'? i really need to polish(eer?) my coding.. |
miran
Member #2,407
June 2002
|
Wel duh! Of course it doesn't compile. You can't use an object before it is created. As a sidenote, it would probably not a bad idea for you to read a book about programming in C++... -- |
GullRaDriel
Member #3,861
September 2003
|
Well, perhaps using this ... "Code is like shit - it only smells if it is not yours" |
miran
Member #2,407
June 2002
|
No, he wants to use the global object named game that is of type game. Which leads me to beleive he doesn't even know what he's doing... -- |
Albin Engström
Member #8,110
December 2006
|
><... thanks guys .. i don't have a book.. and i don't know where to get one that isn't out of date - -.. using this site: "functionx.com" very good.. i think.. i don't read it as much as i need thought.. been using structures like this for a long time without problems.. kinda felt like i used them the wrong way.. apparently... i don't know what i'm doing.. could you tell me how structures should be used then? or direct me to a link so that i wont waste your precious time |
GullRaDriel
Member #3,861
September 2003
|
Well, all done ! Albin can now correct his problem. EDIT: The C way I am using. Can help. Do not take care of what the function do but on how struct is used (and how you access the new created type) n_strlist.h
n_strlist.c
But I think you want C++ and I am bored to do more than a simple copy paste from already written code.
"Code is like shit - it only smells if it is not yours" |
miran
Member #2,407
June 2002
|
Quote: or direct me to a link so that i wont waste your precious time http://www.mindview.net/Books/TICPP/ThinkingInCPP2e.html There should also be a book on plain C there somewhere. Structs are probably explained in it, while the one on C++ only focuses on classes (although the difference between a class and a struct is very small). -- |
GullRaDriel
Member #3,861
September 2003
|
Albin said: i wont waste your precious time Not really, it is 150$/Hour for each, Miran and I. Every started hour is fully accounted. VISA,CB,MASTERCARD,Travelers check accepted.
"Code is like shit - it only smells if it is not yours" |
Neil Black
Member #7,867
October 2006
|
Well then I owe you guys, like, $5,000 each.
|
Albin Engström
Member #8,110
December 2006
|
^^' |
Marco Radaelli
Member #3,028
December 2002
|
Quote: @Marco: textcol1 is obviously the R component of the colour. So you're wrong. Yeah, sorry
|
|