|
-
Jun 20th, 2002, 05:57 PM
#1
Thread Starter
Stuck in the 80s
Question about TypeDef
If I have this:
Code:
typedef struct tagPOINTS {
LONG score, fouls;
} POINTS;
Can I manipulate the data by doing:
Code:
POINTS green;
green.score = 44;
green.founds = 1;
-
Jun 20th, 2002, 06:21 PM
#2
Yup. The typedef struct tagXXXXX is for C programmers. In C, you would find some code like this:
Code:
struct X
{
//... some data...
};
...
struct X y;
y.<something>
By typedefing, you would only have X y as the declaration of the variable.
Z.
-
Jun 20th, 2002, 06:55 PM
#3
Thread Starter
Stuck in the 80s
What you just said confused me All I understood was the "Yes." Would it work as I put it? And what's the difference between what you said?
Me Confused.
-
Jun 20th, 2002, 09:37 PM
#4
typedef is a little like Private type.... End TYpe in VB. Creating a UDT in VB.
It lets you create a name for any datatype you want
Code:
typedef BOOL unsigned integer;
BOOL i; // i is now an unsigned integer
-
Jun 21st, 2002, 12:29 AM
#5
To explain my above post more =). Take a look at the following C++ snippet:
Code:
struct X
{
int y;
};
...
X myX;
myX.y = 10;
Now compare to this C snippet:
Code:
struct X
{
int y;
};
...
struct X myX;
myX.y = 10;
Note the difference in the declaration of myX. To avoid having to type struct over and over again, you can do this:
Code:
typedef struct tagX
{
int y;
} X;
...
X myX;
myX.y = 10;
Z.
-
Jun 21st, 2002, 02:32 PM
#6
Thread Starter
Stuck in the 80s
Alright. Thanks
-
Oct 25th, 2002, 08:34 AM
#7
Thread Starter
Stuck in the 80s
Just to follow this up:
I use classes a lot in my programs now, so I was wondering if there's any real reason to use structs or should I just use classes?
-
Oct 25th, 2002, 09:16 AM
#8
Lively Member
In c++ is a struct not automatically made a type?
-
Oct 25th, 2002, 11:04 AM
#9
jim: you confused the order:
typedef unsigned int BOOL;
would be correct.
In C++ you don't need the struct keyword (or enum, union, whatever) for declaring variables anymore. But if a header file is written for both C and C++ (like windows.h) you'll still find this syntax.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Oct 25th, 2002, 12:39 PM
#10
Monday Morning Lunatic
Originally posted by The Hobo
Just to follow this up:
I use classes a lot in my programs now, so I was wondering if there's any real reason to use structs or should I just use classes?
Using a struct makes it clearer when you're reading that it's not supposed to have object-oriented behaviour (you can inherit structures as well, but they default to public access on all members, so you can use them for small things).
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|