Is it possible to have a structure with a dynamic size? The structure would contain an array.

I know I can use templates, but the size won't be known at compile time. I also know I could just put a dynamic array into it, but that way it would just be a pointer.

I know there would be major issues like how to pass the struct to a function, as it has an unknown size, but to be quite honest I just want pretty code. I'm doing network related operations. I was hoping there'd still be a way to do this using templates or so? I just don't want to go through the hassle of writing a constructor for it to fill in all the fields, and a toByteArray method to convert it back to raw data.

struct MyStruct {
        ulong length;
        ubyte[length] data; // obv won't compile
}

Reply via email to