![](/img/trans.png)
[英]Typedefs, tagged and untagged structures, and incompatible pointer types
[英]Structures incompatible types error
我正在嘗試用 C 編寫撲克游戲。我不允許更改功能:
void eval_strength(struct hand *h){
//mycode
}
void eval_players_best_hand(struct player *p){
int i;
p ->best_hand = p->hands[0];
for(i=0; i <MAX_COMBINATIONS; i++){
if(eval_strength(p->hands[i])) > p->best_hand){
p->best_hand = p->hands[i];
}
}
有人可以幫我解決這些錯誤嗎!
poker.c: In function ‘eval_players_best_hand’:
poker.c:181:15: error: incompatible types when assigning to type ‘struct hand *’ from type ‘struct hand’
p->best_hand = p->hands[0];
^
poker.c:183:21: error: incompatible type for argument 1 of ‘eval_strength’
if((eval_strength(p->hands[i])) > p->best_hand){
在函數 void eval_players_best_hand(struct player *p) 中,我試圖評估數組中每只手的手的強度。 然后我必須將 best_hand 指向最強的手。 eval_strength 是另一個函數,它將根據其強度設置手向量。
eval_strength()
需要一個指向結構手的指針作為參數。 您試圖將實際結構傳遞給它,而不是指向它的指針。
因此,您的if
語句應為:
if(eval_strength(&p->hands[i])) > p->best_hand){
看到不同?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.