简体   繁体   中英

error: invalid type argument of unary '*' (have 'int')

error: invalid type argument of unary '*' (have 'int')

struct test_t {
    int var1[5];
    int var2[10];
    int var3[15];
}

test_t* test;
test->var1[0] = 5;

How can I solve this problem?

You should write:

struct test_t* test;

Or use typedef if you want to avoid writing struct every time you declare a variable of that type:

typedef struct test_t {
    int var1[5];
    int var2[10];
    int var3[15];
} test_t;

test_t* test;

Side note: In C++ the struct name is placed in the regular namespace, therefore there is no need to write struct before declaring a variable of that type.

When you declare a structure variable, struct keyword should be there like

struct test_t* test;

If you don't want to use struct keyword every time you declare a variable, simply use typedef .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM