2014-01-12 105 views
-5

这是C++从 'const int的*' 到 'INT' 无效转换

[错误]从 'const int的*' 到 'INT'[-fpermissive]

void boite(int ligne,int colonne,int i,int s[],int k) 
{ 
    int n; 
    n= s_boite[i][ligne][colonne]; // i numero de la boite 
    for(;n!=0;n/=2) 
     s[k--]=n%2; 
} 

多个添加无效的转换:s_boit

static const int s_boite[8][4][16] = { { {14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7}, { 0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8}, { 4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0}, {15, 12, 8, 2, 4, 9, 1, 7, 5, ...ext 

调用这个函数:

for(i=0;i<8;i++) // appeller les boittes 
{ 
     ligne = resultat[i][0]*2 + resultat[i][5]; // le 1er et le dernier bit converit a au decimal 
     for(j=0;j<4;j++) // 4 bits du milieu 
     {colonne += resultat[i][j+1]*puiss(2,(3-j));}//acumulation en calculant la colone (traduction en decimal) 
     boite(ligne,colonne,i,mat,(4*(i+1)-1)); //mat pour sauvgarder le resultat 
} 
+0

如何在哪里定义s_boite? – lurker

+1

更多信息请..... – haccks

+0

static const int s_boite [8] [4] [16] = { { {{{1,4,4,3,13,1,2,15,11,8,3,10, 6,12,5,9,0,7}, {0,15,7,4,14,2,13,1,10,6,12,11,9,5,3,8}, { 4,1,14,8,13,6,2,11,15,12,9,7,3,10,5,0}, {15,12,8,2,4,9,1,7 ,5,... ext – mohdows

回答

2

这里是没有任何警告编译的代码(稍作修改)。请检查,实际根本原因在哪里:

#include <iostream> 

static const int s_boite[1][1][16] = { { {14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7}}}; 

void boite(int ligne,int colonne,int i,int s[],int k) 
{ 
    int n; 
    n= s_boite[i][ligne][colonne]; // i numero de la boite 
    for(;n!=0;n/=2) 
     s[k--]=n%2; 
} 

int main() { 
     int a[2] = {-1, -1}; 
     boite(0,3,0,a,0); 
     std::cout << "a[0] = " << a[0] << std::endl; // =1 
     return 0; 
} 
+0

我仍然得到相同的错误 – mohdows

+0

@ user3188097我的理解正确你试图编译我的代码版本,它在编译时失败? – vershov

+0

user3188097:你可以发布你用于编译器的确切命令行和你得到的确切输出吗? –

1

我编辑了一下你的源代码,并使用g ++编译了-Wextra和-Wall标志。为我编译,得到了一个警告,因为我拿走了第三个维度。不应该是相关的。

static const int s_boite[8][16] = 
{ 
{14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7}, 
{ 0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8}, 
{ 4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0}, 
}; 

void boite(int ligne,int colonne,int i,int s[],int k) 
{ 
    int n; 
    n= s_boite[i][ligne]; // i numero de la boite 
    for(;n!=0;n/=2) 
     s[k--]=n%2; 
} 

int main(void) 
{ 
     int ess[32]; 
     boite(1, 0, 1, ess, 16); 
     return 0; 
}