How to initialize struct/class on the global scope

前端 未结 3 904
离开以前
离开以前 2021-01-21 05:24

I do now know how to initialize structures on the global scope.

The following is a sample code:

#include
struct A
{
    int x;
};
struct         


        
3条回答
  •  被撕碎了的回忆
    2021-01-21 06:04

    you are doing an assignment outside of any function. In your case you could move only one line of code to get the following:

    #include
    struct A
    {
        int x;
    };
    struct A a;
    int main()
    {
        a.x=6;
    }
    

提交回复
热议问题