class struct?

What are these two? It seems like a class is basiclly a script, but what is a struct?

they’re very similar. In theory, the main difference is data encapsulation: a class offers private members and methods, whereas a struct doesn’t. In practice, that matters less than the “convention” (if you can call it that) of using a struct for little groups of data, as opposed to class which do things. Structs, more often than not, don’t have any methods besides a constructor and just kind of hold data while it’s passed around.

At least that’s my experience.

From a design-point-of-view it is also important to know that structs are value types and not reference types like classes.

value vs. reference

That isn’t true.

Read http://www.dotnetspider.com/kb/Article1034.aspx for a summary of the differences.

-Jon

Huh. Is that different from C++? That’s what I was taught :confused:

In C++ structs could also be private, the difference is that by default a member of a class would be private, and in a struct it would be public. But if you used the “private:” keyword in a struct, they would be private.

Regards,
Afonso

In C++ class vs. struct is just syntax sugar. Basically, these two are exactly the same:

class One {
public:
  // foo
};
struct One {
};

Similarly if you’d write private specifier in a struct. It’s just the default access mode that is different.

In C# it’s different, classes are allocated on the heap and passed by reference; whereas structs are allocated inline (think on the stack for local variables etc.) and are passed by value.

C++ only kept structs to keep compatibility with C structs.

A class is not a script, it’s basically a user-defined data type. Usually you only have one class in per source file though. Also, I’m not sure why, but in C# (just when used with Unity) the script name has to be the same as the class name…

Could someone give me a scripting example of a struct?