Search code examples
c++structurealiastypedef

How to create an alias for a nested structure in C++?


I can't create an alias for a nested structure in C++. Assume that we have this code below. Now, how to create an alias for struct Score using typedef or etc?

struct Information
{
    struct Score
    {
        struct Score *link;
        float src;

    } *src;
};

Solution

  • If struct Score only is declared inside struct Information, you won't be able to use it as its own entity. So break it out.

    struct Score {
        struct Score *link;
        float src;
    };
    
    struct Information {
        struct Score *src;
    };