Download

Recursive struct problems

I’m trying to build a recursive data structure for configuring weapon attachments that can have their own attachments. It’s more than just two levels, because of course you might put a canted rail mount in between them, etc. The intention is that it’s pretty freeform.

The problem I’m running into is that I can’t define the attachment structure ahead of time. If I use a Struct1 as a member of Struct2 (or Struct3 if Struct3 is a member of Struct2) if anywhere in the project Struct2 is a member of Struct1.

To make that statement clearer:

Struct1 contains Struct2. Struct2 can now not contain Struct1.

Struct 1 contains Struct2. Struct 2 contains Struct3. Struct3 can now not contain Struct1.

If you jumble the order up, the same is true. I can’t make Struct2 a member of Struct1 if anywhere down the line Struct1 is a member.

This can’t be by design. It’s irritating and I can’t think of any technical reason for it. At least in C++, direct inheritance has the same problem and causes a build error.

I could use a datatable with the connection between objects just being row names, but that’s not nearly as nice UI-wise.

Why is this like this?