首先,代碼:基礎標識符具有非指針類型
// ...
struct node_list {
node_list *prev;
node *target; // node is defined elsewhere in the application
node_list *next;
};
node_list nl_head;
int main() {
nl_head->prev = &nl_head;
// ...
return 0;
}
我得到一個錯誤:
make (in directory: #####)
g++ -Wall -std=c++11 -o main main.cc
main.cc: In function ‘int main(int, char**)’:
main.cc:38:9: error: base operand of ‘->’ has non-pointer type ‘node_list’
nl_head->prev = &nl_head;
^
Makefile:8: recipe for target 'main' failed
make: *** [main] Error 1
Compilation failed.
至於我可以告訴我的語法是正確的。任何人都可以指出錯誤?
在任何人將其標記爲重複之前,我知道它類似於其他一些問題,但他們的解決方案似乎都不適用於我。除非我做錯了,我承認這是可能的,但這就是我來這裏的原因。
我以爲它必須是' - >',因爲'prev'是一個指針。雖然這確實解決了它,所以我顯然是錯的。謝謝:-) – FatalKeystroke
不客氣:) – edtheprogrammerguy