简体   繁体   English

表达式必须具有指向对象的类型

[英]Expression must have pointer-to-object type

I have the following code in CUDA我在 CUDA 中有以下代码

__global__ void matvec(int *MAT, int *VEC, int *SOL)
{
   int bx = blockIdx.x;
   int tx = threadIdx.x;
   int i = 32*bx+tx;
   for (int j = 0; j < X; j++){
    SOL[i] = ((MAT[i][j] * VEC[j]) + SOL[i]) % 2;
   }
}

My problem is that in line 6 I have an error.我的问题是在第 6 行我有一个错误。 It says that my expression must have a pointer-to-object type.它说我的表达式必须有一个指向对象的类型。

The reason for the error is that you are treating a pointer as a 2D array.错误的原因是您将指针视为二维数组。 You define MAT as int *MAT , but you access it as MAT[i][j] .您将MAT定义为int *MAT ,但您将其作为MAT[i][j]

Assuming you have correctly allocated MAT , I would change this to MAT[i*X + j] .假设您已正确分配MAT ,我会将其更改为MAT[i*X + j] Alternatively, define MAT as int **MAT , again, assuming you have allocated it correctly.或者,再次将MAT定义为int **MAT ,假设您已正确分配它。

(BTW, this is not a CUDA problem, it is a simple C syntax error.) (顺便说一句,这不是 CUDA 问题,而是一个简单的 C 语法错误。)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 error:expression必须具有指向对象的指针类型 - error: expression must have pointer-to-object type C++ 表达式必须具有指向对象的类型 - C++ Expression must have pointer-to-object type 下标要求数组或指针类型表达式必须具有指针到对象的类型 - subscript requires array or pointer type expression must have pointer-to-object type 表达式必须具有指针到对象的类型,下标需要数组或指针的类型 - expression must have pointer-to-object type,subscript requires array or pointer type MSVC - 表达式必须具有指向对象的类型,但它在泛型数组上具有“float”类型? - MSVC - expression must have pointer-to-object type but it has type "float" on generic array? 函数内部的 C++ 错误:表达式必须具有指向对象的类型 - C++ error inside function: expression must have pointer-to-object type 如何修复IntelliSense:表达式在MFC中必须具有指向对象的指针类型? - How to fix IntelliSense: expression must have pointer-to-object type in MFC? 如何修复错误“表达式必须具有指向对象类型”(多文件项目)? - How can I fix the error “expression must have pointer-to-object type” (multifile project)? 对于c ++中的数组,什么是“表达式必须具有指向对象的指针类型”? - What is “expression must have pointer-to-object type” for arrays in c++? C ++“表达式必须具有指向对象类型的指针”和“下标需要数组或指针类型”是什么意思? - What does C++ mean by "expression must have pointer-to-object type" and "subscript requires array or pointer type"?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM