从'const int*'到'int'的转换无效

invalid conversion from 'const int*' to 'int'

本文关键字:int 转换 无效 const      更新时间:2023-10-16

这是C++

[错误] 从"const int*"到"int"的转换无效 [-允许]

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 
}

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

#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;
}

我稍微编辑了一下源代码,并使用带有 -Wextra 和 -Wall 标志的 g++ 进行编译。为我编译,收到警告,因为我拿走了第三维度。应该不相关。

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;
}