473,397 Members | 2,056 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Differences between struct and class

what are the most usable, prominent, and must-to-know ones?
Oct 8 '08 #1
4 1141
On Tue, 07 Oct 2008 20:04:03 -0700, puzzlecracker <ir*********@gmail.com>
wrote:
what are the most usable, prominent, and must-to-know ones?
http://msdn.microsoft.com/en-us/library/aa664471.aspx
Oct 8 '08 #2
puzzlecracker wrote:
what are the most usable, prominent, and must-to-know ones?
From a previous post you seem to be thinking of the C# type system in
terms of C++. You cannot do this, often the primary differences between
languages are their types systems. For instance C uses a "tag" system,
C++ uses a "type" system where everything is a "type" i.e. a class (well
except fundamental types, anyways, we're not talking C++).

In C# there is are two fundamental types Value types (structs) and
Reference types (classes). This effects, primarily their equality and
assignment semantics, and thus the way they are passed as parameters to
methods. These semantics permeate everything, it is not like C++ where
parameters are passed by value by default but can be pass by reference
using the reference operator (&). There is no such construct on C#,
value types are value types and reference types are reference types,
forever. Well not quite, you can "box" a Value type into a Reference
type, something that should generally be avoided.
Oct 8 '08 #3
On Oct 8, 7:04*am, puzzlecracker <ironsel2...@gmail.comwrote:
what are the most usable, prominent, and must-to-know ones?
This is a FAQ. Here's a Google Groups link to the last (as far as I
remember) discussion on the topic - it has my long post, and I do not
want to retype it :)

"Why are some types implemented as struct?":
http://groups.google.com/group/micro...45559a938e1af0
Oct 8 '08 #4
puzzlecracker wrote:
what are the most usable, prominent, and must-to-know ones?
The most fundamental is that a class is a reference type and a struct is
a value type.

To work well, a struct should be small and immutable. The members of a
struct are generally value types (with a possible exception for strings,
as they are also immutable).

If you don't have any special reason to use a struct, stick to creating
classes.

--
Göran Andersson
_____
http://www.guffa.com
Oct 8 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Bern | last post by:
what are all the diferences between the two?
22
by: BekTek | last post by:
Hi.. I'm so sorry about that I've postes so many questions recently.. :) I'm still confused about the differences between malloc and operator new.. I know that when we work with class object and...
6
by: gustav04 | last post by:
hi all i have a question: what is the difference between a c-function and an c++ class method (both do exactly the same thing). lets say, i have a function called print2std() and a class...
12
by: Jason Curl | last post by:
Hello, Just a clarification of the specification about the C-Standard's interpretation of pointers. I know that 'char *' and 'void *' are equivalent and that 'int *' may be different in...
15
by: Paul Morrison | last post by:
Hi all, I need to come up with some differences between arrays in Java and C, I have searched Google and so far all I have found is the following: Arrays in Java are reference types with...
11
by: blangela | last post by:
I am teaching a C programming course to C++ programmers and want to come up with list of _KEY_ differences between the two languages. Below is a list I have come up with so far. Have I missed any?...
2
by: Ninereeds | last post by:
I'm messing around with using mixin-layers (look for papers by Yannis Smaragdakis and Don Batory) to define data structures. One issue is that nodes tend to have pointers to other nodes - the...
2
by: Javier | last post by:
Hi, I have just read that struct's in C++ can have public and private members, so I have one question: Which are the differences between classes and structs (besides constructors and...
9
by: chikkubhai | last post by:
Why is the result different for the following set of two code snippets Code without using this pointer #include <string> #include <iostream> using namespace std; struct X { private:
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.