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