【问题标题】:member reference type is a pointer; did you mean to use '->'? [closed]成员引用类型是指针;你的意思是使用'->'吗? [关闭]
【发布时间】:2019-02-08 00:11:41
【问题描述】:
GpuContext* ctx

struct GpuContext
{
/*Input vars*/
size_t deviceIdx;
size_t rawIntensity;
size_t workSize;
int stridedIndex;
int memChunk;
bool isNVIDIA = false;
int compMode;

/*Output vars*/
cl_device_id DeviceID;
cl_command_queue CommandQueues;
cl_mem InputBuffer;
cl_mem OutputBuffer;
cl_mem ExtraBuffers[6];
cl_program Program[2];
cl_kernel Kernels[2][8];
size_t freeMem;
int computeUnits;
std::string name;

uint32_t Nonce;

};

ctx->Program[ii].getBuildInfo((cl_int*)1);

我正在尝试运行最后一行代码。我为函数的其余部分提供了相关代码。 ii 是因为我正在运行的代码在循环内。 getBuildInfo 是来自位于此处的 cl_program 类的函数调用:

https://github.khronos.org/OpenCL-CLHPP/classcl_1_1_program.html

我知道我做错了什么。我要做的是在 Program[ii] cl_program 对象上调用函数 getBuildInfo 。编译器告诉我

member reference type 'cl_program' (aka '_cl_program *') is a pointer; did
  you mean to use '->'?
                    ctx->Program[ii].getBuildInfo((cl_int*)1);
                    ~~~~~~~~~~~~~~~~^
                                    ->

但是 Program[ii] (cl_program) 不是你从 struct GpuContext 中看到的指针。 ctx->Program[ii]->getBuildInfo((cl_int*)1); 正确吗?

【问题讨论】:

  • 您提供的链接没有显示cl_program的定义。
  • 好吧,编译器说明了一切:cl_program 似乎是_cl_program* 的类型别名。这就是为什么您需要使用运算符->
  • 您可能已经删除了GpuContext 的几乎所有成员,但仍然显示问题。不要让人费解无关紧要的细节来帮助你。

标签: c++


【解决方案1】:

cl_program 只是typedef_cl_program*,其中_cl_program 是一个结构。结果Program[ii]实际上是一个指针,错误信息是有道理的。

【讨论】:

  • 哦,好的。那么箭头操作符会是正确的吗?
  • @thecodingmate 没错;此处应使用箭头运算符。
猜你喜欢
  • 2019-10-20
  • 2018-04-03
  • 1970-01-01
  • 2021-06-29
  • 1970-01-01
  • 2021-09-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多