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
是个坏主意。。。