I have dynamically created an Sensor object with new. However, when I try to use the object, it looks like the Sensor's members are uninitialized. I have verified that the creation and initialization of the object is successful. I don't believe this problem is due to the global object not being static but, changing it doesn't resolve the issue either.
class SensorModule
{
public:
SPI_BUS* spi;
ADX123* accel;
SENSOR* sensor2;
...
public:
SensorModule();
~SensorModule();
public:
sendCommand();
...
}
SensorModule::SensorModule()
{
spi = new SPI_BUS(1,2,3);
accel = new ADX123(spi,4);
sensor2 = new SENSOR(spi,5);
...// more initialization
}
void SensorModule::sendCommand(void){
accel->accelCommand(); // When I debug and stop here, I see that my "this"
// accel pointer are uninitialized
// however, the SensorModule object pointer is
// valid in the heap
}
main.cpp
SensorModule* pModule = NULL;
int main(void)
{
pModule = new SensorModule();
pModule->sendCommand();
...
for(;;)
{}
}