|
-
January 10th, 2011, 10:43 AM
#1
Struct vs Class, take II
 Originally Posted by amira7
Besides the visibility of members,
Structs are value types and classes are reference types.
As you know, value types are allocated on the stack or inline as a part of another object while classes are allocated on the heap.
Struct is often a small object that needs to be treated like a primitive type while classes are normally used for implementation requiring more processing power. In other words, classes would normally be used to implement a piece of business logic, rather than to support data related or primitive-type objects.
I hope this clears it up a bit.
Although your description roughly follows common usage I think it's worth mentioning that the roles you assign to the class and the struct are a historical convention and nothing that's stipulated by the language.
In fact the struct and the class are conceptually equivalent in C++. Nothing prevents anyone from using them in the exact opposite manner from what you state.
I mention this because making struct and class to be equals was a very important design decision as explained by Stroustrup in The Design and Evolution of C++ on page 76.
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
|