error: invalid type argument of ‘->‘ (have ‘int‘)
程序员文章站
2022-06-22 19:58:01
...
for语句内定义变量出错
写了一个对链表进行排序的函数(虽然用处不大,但是万一呢),敲完就报错。
for(int i = 0 ,p = pHead->pNext; i < len-1 ; ++i ,p = p->pNext)
{
for(int j = i+1 ,q = p->pNext ; j < len ; ++j ,q = q->pNext )
{
if(p->data > q->data)
{
int t = p->data;
p->data = q->data;
q->data = t;
}
}
}
由于最近一段时间经常用C++,所以在使用for循环时喜欢直接定义一个循环变量,然后,上面这段代码一直报错。
error: invalid type argument of '->' (have 'int')
看到错误提示时没太明白什么意思,后来去看错误的那几行代码发现,将p和q重新定义为int型的变量,所以->就变无效(在源代码中PNODE是一个结构体指针类型,p和q定义为结构体指针类型的变量)。
推荐阅读
-
Xcode版本问题:Unknown argument type ‘__attribute__‘ in method -[RCTAppState getCurrentAppState:error:].
-
kotlin出现error: invalid argument: -include-runtime错误的解决方法
-
[VUE ERROR] Invalid prop: type check failed for prop "list". Expected Array, got Undefined
-
Module build failed: TypeError [ERR_INVALID_ARG_TYPE]: The “from“ argument must be of type string
-
[VUE ERROR] Invalid default value for prop "slides": Props with type Object/Array must use a factory function to return the default value
-
invalid argument “xx:v1.0“ for t: Error parsing reference: “xx:v1.0“is not a valid repository/tag: r
-
error: invalid type argument of ‘->‘ (have ‘int‘)
-
RuntimeError: Expected tensor for argument #1 'indices' to have scalar type Long; but got CUDAType
-
RuntimeError: Expected object of scalar type Long but got scalar type Int for argument #2 'target'
-
RuntimeError: Expected tensor for argument #1 ‘indices‘ to have scalar type Long; but got CUDAFloatT