If I have this:
Can I manipulate the data by doing:Code:typedef struct tagPOINTS {
LONG score, fouls;
} POINTS;
Code:POINTS green;
green.score = 44;
green.founds = 1;
Printable View
If I have this:
Can I manipulate the data by doing:Code:typedef struct tagPOINTS {
LONG score, fouls;
} POINTS;
Code:POINTS green;
green.score = 44;
green.founds = 1;
Yup. The typedef struct tagXXXXX is for C programmers. In C, you would find some code like this:
By typedefing, you would only have X y as the declaration of the variable.Code:struct X
{
//... some data...
};
...
struct X y;
y.<something>
Z.
What you just said confused me :confused: All I understood was the "Yes." Would it work as I put it? And what's the difference between what you said?
Me Confused.
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
To explain my above post more =). Take a look at the following C++ snippet:
Now compare to this C snippet:Code:struct X
{
int y;
};
...
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:struct X
{
int y;
};
...
struct X myX;
myX.y = 10;
Z.Code:typedef struct tagX
{
int y;
} X;
...
X myX;
myX.y = 10;
Alright. :) Thanks
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?
In c++ is a struct not automatically made a type?
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.
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).Quote:
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?