从'const int*'到'int'的转换无效
invalid conversion from 'const int*' to 'int'
这是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;
}
相关文章:
- 是否可以从int转换为enum类类型
- 如何在C++中将一个无符号的 int 转换为两个无符号的短裤?
- 是什么导致了这种使用三进制而不是短整型的有符号int到无符号int转换
- 将字符串中的 int 转换为字母;
- 主.cpp:18:20:错误:从"int*"转换为"int"会失去精度 [-fa
- 将非常大的 int 转换为双倍,在某些计算机上会损失精度
- 如何将矢量<int>转换为字符数组?
- C++ 无法从 const int* 转换为 const_iterator
- 我不断收到错误 C2440'=':无法从"int *(__cdecl *)(int *,int *,int,int)"转换为"int *
- 如何将 int[4] 转换为 std::array<int,4>?
- 如何将data[i].int转换为vaible
- 将 int 转换为字符串,然后连接另一个变量以创建完整扩展名,然后将其转换为 const_char*
- 将私有矩阵形式 int 转换为双 C++
- 无法将参数 1 从 'int' 转换为 'int &'
- 将 int 转换为字符串后始终得到 0
- isspace 函数的性能警告,从 int 转换为布尔值
- 将大 int 转换为浮点数,而不舍入 c++
- 错误:无法将'uint8* {aka unsigned int*}'转换为"常量emxArray_uint8_T*"?
- 将未签名的INT转换为BCD
- 在 C++ 中将 int 转换为双精度