Reputation: 131
I'm trying to understand managed/unmanaged code as it pertains to structs and classes. I have a struct with a property of another struct but its a pointer declaration as in:
struct StateInfo
{
Bitboard board;
StateInfo* previous;
}
I'm converting a C++ project to C#. Anyways, this doesn't work because Bitboard is a class. The error I get is something to the fact that pointers cannot be declared on managed types. If I take out Bitboard from the struct, it's fine. I need it though so I changed Bitboard from a class to a struct, and all is good. I'm not sure what's up? Any ideas?
Upvotes: 2
Views: 457
Reputation: 14002
Essentially, in c# all objects are automatically a pointer and do not need to be released.
Try reading some transitional articles about moving from C++ to C# C++ -> C#: What You Need to Know to Move from C++ to C#
Upvotes: 0
Reputation: 210445
I suggest you read about blittability.
Blittable types have the same binary representation in managed and unmanaged code, and you need to represent them the same way if you want pointers to make sense.
Upvotes: 0
Reputation: 161773
You probably don't even want a struct
. Instead:
class StateInfo
{
Bitboard board;
StateInfo previous;
}
In C#, a struct
is a value type. For instance, int
is a struct
. They should typically be used for things which are entirely described by their value.
Upvotes: 2