2016-07-15 3 views
-1

警告を解決する方法を知っている人は誰でも知っていますか?new_costを返すと、returnはキャストのない整数からポインタを作る[デフォルトで有効にする]

int *cost(int num_nodes, edge new_solution[][10]) 
{ 
    int new_cost = 0; 
    int num_edges = 1; //set number of edges back to default 
    int x, y, weight; 

    for (x = 1; x <= num_nodes; x++) //print out new_solution 
    { 
     weight =0;//find the largest tx on each node 
     for (y = 1; y <= num_nodes; y++) 
      if (new_solution[x][y].label == 1) 
      { 
       printf("\n Edge %d:(%d %d) energy:%d", 
         num_edges++, x, y, new_solution[x][y].weight); 
       if (weight < new_solution[x][y].weight) //find highest energy used per node 
       { 
        weight = new_solution[x][y].weight; 
        //printf("\n weight:%d accum:%d", weight, new_cost); 
       } 
      } 
     new_cost += weight; //find total weight 
    } 
    printf("\n Total cost is %d\n\n", new_cost); 
    return new_cost; 
} 

重み変数を配列に割り当てることができないためですか?私はコストを返すために以下の関数について同じ警告を受け取ります。誰もこれを解決する方法を知っていますか?

int *acceptance_prob(float T, int old_cost, int new_cost, edge new_solution[][10], 
        edge current_SA[][10], FILE *fp, int num_nodes) 
{ 
    int delta = 0, x, y; 
    float ap = 0.0; 
    int cost; 

    delta = (old_cost - new_cost); 
    ap = (exp(delta/T)); //this is the typical equation used 

    if (new_cost < old_cost)//if new_solution has less energy select it 
    { 
     fprintf(fp, "NO"); 
     for (x = 1; x <= num_nodes; x++) 
      for (y = 1; y <= num_nodes; y++) 
       current_SA[x][y] = new_solution[x][y]; 
     old_cost = new_cost; 
    } 
    else //if new_solution uses more energy maybe select it 
    { 
     if (ap > rand_float()) 
     { 
      fprintf(fp,"YES"); 
      for (x = 1; x <= num_nodes; x++) 
       for (y = 1; y <= num_nodes; y++) 
        current_SA[x][y] = new_solution[x][y]; 
      old_cost = new_cost; 
     } 
    } 
    cost = old_cost; 

    return cost; 
} 
+0

この質問は、Cについてであり、C++ではないようです。その場合は、C++タグを削除してください。 –

+2

C++で正確に同じエラーが発生し、その答えが同等に適用されます。 2つの言語、確かに、しかし、あまりにも熱心にならないようにしましょう。 – MSalters

答えて

6

誰もが、私は警告を解決する方法を知っています。returnは、キャストなしで整数からポインタになります[デフォルトで有効になって]私はnew_costを返すとき?

関数の戻り値の型をint*からintに変更します。

その関数からint*を返すことは、とにかく意味がありません。

+0

ありがとう、それを変更し、それは働いた –

+0

@ J.DOLE、あなたは大歓迎です。ハッピープログラミング。 –

関連する問題