Results 1 to 10 of 10

Thread: Question about TypeDef

  1. #1

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256

    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;
    My evil laugh has a squeak in it.

    kristopherwilson.com

  2. #2
    Zaei
    Guest
    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.

  3. #3

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    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.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  4. #4
    jim mcnamara
    Guest
    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

  5. #5
    Zaei
    Guest
    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.

  6. #6

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Alright. Thanks
    My evil laugh has a squeak in it.

    kristopherwilson.com

  7. #7

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    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?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  8. #8
    Lively Member FantastichenEin's Avatar
    Join Date
    Mar 2000
    Location
    dairy
    Posts
    106
    In c++ is a struct not automatically made a type?
    ****

  9. #9
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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.

  10. #10
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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
  •  



Click Here to Expand Forum to Full Width