How to initialize struct/class on the global scope

前端 未结 3 937
离开以前
离开以前 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:05

    The problem you are observing is not related to including glut. The compiler does not allow you to assign value to a structure in the global scope. You can achieve what you want either by calling a constructor of the structure(which would be allowed at global scope) or by calling the assignment in some function.

    EDIT: here is a somewhat related discussion: Why can't I access my array subscript in global scope

提交回复
热议问题