Results 1 to 8 of 8

Thread: Structs...

  1. #1

    Thread Starter
    Addicted Member Virtual24's Avatar
    Join Date
    May 2001
    Posts
    228

    Question Structs...

    Two questions:

    1) Do structs need constructors/destructors and if not, can they have them.

    2) Can you declare anything in a struct as private or protected, or does everything have to be public ( by default ).

    If anyone knows the answers to these questions it would help out a lot. ~Thanx~
    To protect time is to protect everything...

  2. #2
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    structs ARE classes, except that everything is BY DEFAULT public instead of private. Other then that, there is no difference, so, yes, they CAN, but dont HAVE to have constructors/destrcutors, and they CAN have private or protected sections.

    Z.

  3. #3

    Thread Starter
    Addicted Member Virtual24's Avatar
    Join Date
    May 2001
    Posts
    228
    Haha, thanx for helping me... Sorry if it sounded like i was yellng with the bold type and all. :-)
    To protect time is to protect everything...

  4. #4
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    Yes, while you MIGHT have SOUNDED like you were YELLING, I got the picture =).

    Z.

  5. #5
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    But if you use structs this way, you might just as well use a class, which makes the code more readable.
    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.

  6. #6
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    Originally posted by CornedBee
    But if you use structs this way, you might just as well use a class, which makes the code more readable.
    True, CB. THe most I will add onto a struct is a constructor or destructor, but only then when It is something like a linked list node (zero out the pointers). Anything more is a class.

    Z.

  7. #7
    Member
    Join Date
    Oct 2002
    Location
    Look out your window.
    Posts
    54
    In my little book it here... ehh it says

    A structure is a class declared with the class-key struct.
    And further on it basically says that structs were put in C++, so that you could use old C code that say took a struct as a parameter.

  8. #8
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Exactly. The struct keyword is not necessary in C++. It is there for backwards compatibility mainly.

    The struct keyword in C++ shouldn't be used differently than in C. This means no methods, no access specifiers, no derivation. Maybe a constructor or destructor. But only if it really makes sense.
    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.

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