ManiAm
ManiAm

Reputation: 1841

Nested Structure with anonymous type in C++

I am trying to port a nested struct code in C into C++. I know that in C++ the inner structure type will be a member of outer struct type. In my case, I have an inner struct that has no type (marked with *), and I do not know how to fully specify struct2 to the compiler.

typedef struct struct1
{
    struct // *
    {
        struct struct2
        {
            int bla;
            int bla2;
        } *array;

        int bla3;

    } list;

    int bla4;

} struct1_t;


int main()
{
    struct1_t *st = new struct1_t();

    st->bla4 = 10;
    st->list.bla3 = 45;

    // ?
    st->list.array = new struct1_t::struct2();


    return 0;
}

Edit: the structure code above is generated automatically by the ASN1 compiler and I can not make any changes to it.

Upvotes: 2

Views: 283

Answers (1)

mark
mark

Reputation: 5469

This works for me in C++11:

st->list.array = new decltype( struct1_t::list )::struct2;

Upvotes: 3

Related Questions