|
-
Oct 15th, 2002, 09:23 PM
#1
Thread Starter
Addicted Member
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...
-
Oct 15th, 2002, 10:13 PM
#2
Frenzied Member
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.
-
Oct 15th, 2002, 11:16 PM
#3
Thread Starter
Addicted Member
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...
-
Oct 16th, 2002, 12:39 AM
#4
Frenzied Member
Yes, while you MIGHT have SOUNDED like you were YELLING, I got the picture =).
Z.
-
Oct 16th, 2002, 08:43 AM
#5
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.
-
Oct 16th, 2002, 10:42 AM
#6
Frenzied Member
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.
-
Oct 16th, 2002, 11:01 AM
#7
Member
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.
-
Oct 16th, 2002, 11:10 AM
#8
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|