Thread: Understanding typedef...

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    56

    Unhappy Understanding typedef...

    Hello,
    I have an exam on c++ tomorrow, but unfortunately, i lost my only sheet on typedef.

    I am a beginner in C++, and i have just finish studying Array(1 dimension).

    My teacher said that if we have to input name(Which is more than one character)in the array, we should use "typedef", and strcpy or strcmp.

    I think typedef is something like:

    typedef char name[15];
    typedef name namelist[50];
    ...
    i don't know what 's that mean at all.
    please help.

    Thanks

  2. #2
    CS Author and Instructor
    Join Date
    Sep 2002
    Posts
    511

    Wink

    typedef's are ways we can create aliases. It does not create a new data type however.

    Do you have your text to help you study? Also, look at tutorials on line if you are not sure.
    Mr. C: Author and Instructor

  3. #3
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Building upon what Mister C said a typedef would work sort of like:

    #define page int

    However it is a bit more structured. The compiler refers to it by the typedef alias rather than the data type that it aliases. However, its use is the same as the data type it aliases. In C, for example:

    Code:
    struct my_struct {
       int first, second, third;
    };
    
    struct my_struct whatever;
    But typing struct is no fun so most do this:

    Code:
    typedef struct my_struct my_struct;
    
    my_struct whatever;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Need help understanding info in a header file
    By hicpics in forum C Programming
    Replies: 8
    Last Post: 12-02-2005, 12:36 PM
  3. Please STICKY this- vital to MSVC 6 dev - BASETSD.h
    By VirtualAce in forum Game Programming
    Replies: 11
    Last Post: 03-15-2005, 09:22 AM
  4. build errors migrated from dx9b to dx9c sdk
    By reanimated in forum Game Programming
    Replies: 4
    Last Post: 12-17-2004, 07:35 AM
  5. oh me oh my hash maps up the wazoo
    By DarkDays in forum C++ Programming
    Replies: 5
    Last Post: 11-30-2001, 12:54 PM