C++ This declaration does not contain a storage class or type specification



  • struct st1 {
        string name[2];
        bool active[2];
    };
    struct st2;
    void init() {
        struct st2 {
            st1 tier1;
            st1 tier2;
            tier1";
        }
    };
    

    I created a structure. st1 and tried to use it twice in the structure. st2♪ As far as I'm concerned, it's what you need to add, but Visual studio 2019 shows a mistake. это объявление не содержит класс хранения или спецификатор типа on line tier1; (if you write, for example, tier1.name[0]="Имя"; or replace all the masses by a few variables, nothing is changed.

    So I tried to initialize the structure. st2 Outside, but the result was still the same.



  • You have a structure. st2 field present st2 It probably makes mistakes. If I understand you correctly, it's a function. init() I was added to the unsatisfactory, so I took it away. As a result, when writing the structure:

    #include <string>
    

    struct st1 {
    std::string name[2];
    bool active[2];
    };
    struct st2 {
    st1 tier1;
    st1 tier2;
    };

    int main()
    {
    st2 c;
    c.tier1.name[0] = "5";
    }

    No mistakes arise and a copy of the structure that we can edit is being produced calmly, and I have changed for example. name[0] Ooh. tier1That's what happened after the code was completed:

    введите сюда описание изображения



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2