上級 › error: invalid type argument of '->' の原因と直し方 › パターン1
error: invalid type argument of '->' の原因と直し方
構造体そのものの変数に対して->を使おうとしたときに出るエラーです。
1 #include <stdio.h> 2 3 struct Point { int x; }; 4 5 int main(void) { 6 struct Point a = {5}; 7 printf("%d\n", ____); ^ 8 return 0; 9 }
main.c:7:21: error: invalid type argument of '->' (have 'struct Point')
空欄を埋めてコンパイル・実行を通す
aは構造体そのもの(ポインタではない)なので、メンバアクセスには.を使います。->は構造体へのポインタ専用です。
次の問題