Variable length struct in C++

since it’s a POD, everything works just like it did in C. - SO

struct var
{
    int a;
    int b[1];

    static std::shared_ptr<var> make_var(int num_b) {
        const extra_bytes = (num_b ? num_b-1 : 0)*sizeof(int);
        return std::shared_ptr<var>(
                new char[sizeof(var)+extra_bytes ],
                [](var* p){delete[]((char*)(p));});
}
Written on June 3, 2021, Last update on June 13, 2021
c++ array