Hi ,
I am confused about what typedef means ?
for example:
"typedef double something; "
what exactly does this mean??
Thanks for any explanation!!
Hi ,
I am confused about what typedef means ?
for example:
"typedef double something; "
what exactly does this mean??
Thanks for any explanation!!
To define your own type based on other existing data types.
the syntax:
where existing_type is a C++ fundamental or any other defined type and new_type_name is the name that the new type we are going to define will receive. For example:Code:typedef existing_type new_type_name ;
typedef char C;
typedef short unsigned int USHORT;
then just use the new type word to declare variables
C 'a';
USHORT 5;
Typedef enforces strong typing, in accordance with general C++, therefore use this over Macro's..
--Placid
it's the method for creating a type based on some other type in C/C++. Many people, not including myself will use it to create a name for a pointer to something. for instance:
typedef int *intptr;
then you can use it to make a pointer to an int later in your code.
intptr ptr1;
int *ptr2;
ptr1 and ptr2 are essentially the same thing. Get it?
"You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter
beat me to it.
"You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter
If it helps, I think you explained it better
--Placid
oh thanks a lot. shheeeeesshhh
"You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter
For an example of how to abuse typedef consult the windows.h header file.
it's also useful to substitute a shorter name for a type (which is always useful in avoiding typos).
ie:
typedef typename std::vector<Wrapper_of_type<T> >::iterator iter;
for (iter i=begin(); i != end(); ++i) ...
any change in the long name could be made at one place instead of many.
Yeah, doing something like:
std::vector<std::vector<float> > f(rowcount, std::vector<float>(colcount));
is not as nice as:
typedef std::vector<float> row;
typedef std::vector<row> fArray;
fArray f(rowcount, row(colcount));