错误:数组下标'int[int]'的类型无效
error: invalid types 'int[int]' for array subscript
#include <iostream>
using namespace std;
int t,n,k,m,i,j;
int l[100002],r[100002],c[100002],a[100002],total=0;
int swap( int *a, int *b)
{
int temp=*a;
*a=*b;
*b=temp;
}
int pivot( int l, int h)
{
int x=c[h],i=l,j=l-1,temp;
for(i=l;i<h;i++)
{
if(c[i]<x)
{
j++;
swap(&c[i],&c[j]);
swap(&r[i],&r[j]);
swap(&l[i],&l[j]);
}
}
j++;
swap(&c[h],&c[j]);
swap(&l[h],&l[j+1]);
swap(&r[h],&r[j+1]);
return j;
}
int quick( int l, int h)
{
int p;
if(l<h)
{
p=pivot(l,h);
quick(l,p-1);
quick(p+1,h);
}
}
int main() {
cin>>t;
while(t--)
{
total=0;
cin>>n>>k>>m;
for(i=1;i<=n;i++)
{
cin>>a[i];
total+=a[i];
}
for(i=1;i<=m;i++)
cin>>l[i]>>r[i]>>c[i];
quick(1,m);
for(i=1;i<=m;i++)
cout<<l[i]<<r[i]<<c[i]<<endl;
}
return 0;
}
在上面的代码中,我得到了以下错误:
prog.cpp: In function 'int pivot(int, int)':
prog.cpp:21:13: error: invalid types 'int[int]' for array subscript
swap(&l[i],&l[j]);
^
prog.cpp:21:19: error: invalid types 'int[int]' for array subscript
swap(&l[i],&l[j]);
^
prog.cpp:26:11: error: invalid types 'int[int]' for array subscript
swap(&l[h],&l[j+1]);
^
prog.cpp:26:19: error: invalid types 'int[int]' for array subscript
swap(&l[h],&l[j+1]);
^
你能找出错误是什么吗?我也想知道为什么我只在数组l
中得到这个错误,而不是在r
或c
中。所以请也解释一下这个。
这是上述程序的链接。
http://ideone.com/K1exEKl
为int
类型的函数参数,隐藏同名全局变量
相关文章:
- 为什么 int 类型的枚举类值不能用作 int
- 如何将文本文件的特定行读取到 int 类型的数组中C++?
- int* 和 int[] 类型对二进制运算符 + 的操作数无效
- 比较两个整数在C++中与未知 int 类型的相等性
- 二进制'operator+' 'int*'和'int*'类型的无效操作数
- 使用元编程选择 int 类型,将生成错误
- 从数组创建 Mat 时,'cv::Mat' 和 'int' 类型不兼容
- 复制初始化 - 从 'int' 类型转换为非标量类型
- 初始化cv :: mat ::具有int类型的定义大小的人
- 处理代码重新定义int类型(uint16_t,int16_t等),并不喜欢它
- 为什么没有"int"类型声明时输出不同?
- 在大型程序中将长变量更改为 int 类型
- 无法将 int 类型转换为时间类型(我的类类型)
- C++:无法在按位函数后将 int 类型设置为非标量
- 无法分配给INT类型的成员[10]
- C++ cin 将字符串读取到 int 类型中返回 0
- 为什么 decltype((i)) 是引用类型,而 decltype(i+0) 是 int 类型
- 使用4用于循环的4矩阵上的数组下标的“ int [int]类型”
- std::is_arithmetic 为通用 lambda 中的 int 类型返回 false:未定义的行为?
- 正在施放带有“ Int”类型的临时性