Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 指针类型表C++;_C++_Arrays_Casting - Fatal编程技术网

C++ 指针类型表C++;

C++ 指针类型表C++;,c++,arrays,casting,C++,Arrays,Casting,我有一个表变量: /// Place all your sensors in this table static DetectionSensor *DetectionSensors[] = { &Sensor200BP203, &SensorXXXX, } 我将其传递给一个方法: DetectionThread.create((void*)DetectionSensors); 在我的DetectionThread中,我有一个成员: private :

我有一个表变量:

/// Place all your sensors in this table 
static DetectionSensor *DetectionSensors[] = {
      &Sensor200BP203,
      &SensorXXXX,
}
我将其传递给一个方法:

DetectionThread.create((void*)DetectionSensors);
在我的DetectionThread中,我有一个成员:

private :
        DetectionSensor *pDetectionSensors[];
在DetectionThread的方法中,我希望像这样转换参数:

void Detection::setup()
{
    *this->pDetectionSensors = ((DetectionSensor *)this->parameters);
}

当我执行我的程序时,我有一个错误…

您的代码不清楚。一方面,您谈论方法
创建
,另一方面,您展示方法
设置
。那么
create
serup
之间的关系是什么呢?参数的类型是什么

在任何情况下,都不能编译代码,因为不能定义不完整的非静态数据成员。所以这个定义

private :
        DetectionSensor *pDetectionSensors[];
这是错误的

考虑到DetectionSensors作为参数通过值传递时的类型为

DetectionSensor **pDetectionSensors;

并且您不能为数组分配地址。

您没有为
pDetectionSensors
分配内存,因此您不能使用
*pDetectionSensors
。您对强制转换不小心。这会咬你的。您正在将
DetectionSensor**
转换为
void*
,但将转换回
DetectionSensor*
“我有一个错误”这一选项。完全晶莹剔透。而且
检测传感器
神奇地变成
检测
。这个问题很不清楚。顺便说一句,调用双指针变量
DetectionSensors
是个坏主意。。。