Dereference a pointer?

A want to get a value of public variable in an instance of a class.
I'm passing an pointer of an instance into Relay. The instance has a boolean deviceState.

class Relay : public Device
{
   public:
   Relay(uint8_t in_pin, Device *in_dependent_device) {
       dependent_device = in_dependent_device;
       Serial.print(dependent_device->deviceState);
   };
   Device *dependent_device;

}

The serial print would yield 129. I'm assuming that's an address and not the value of deviceState which should either be 0 or 1.
I've also tried

dependent_device = &in_dependent_device;

but it also yield another address.

If you can get the value that would be awesome.
thanks.

What code are you using to call this constructor method Relay() ?

You might want to call the constructor for Device.

 Relay(uint8_t in_pin, Device *in_dependent_device) : 
  Device(...),
  dependent_device(in_dependent_device)
{
       // dependent_device = in_dependent_device;
       Serial.print(dependent_device->deviceState);
 };

But then I am not sure why Relay inherits from Device and has the constructor argument in_dependent_device.
You will need to post more code for more answers :wink:

Cheers!

The code is too massive to show. I'll write up a simpler model when get the chance. Im getting a headache all of a sudden. Straining too much at the monitor I guess.

mistergreen:
The serial print would yield 129. I'm assuming that's an address and not the value of deviceState which should either be 0 or 1.

Looks like it's not. Your code is correct, and nevertheless 129 is pretty low for an address

Yeah, I made a quick test to see... everything turned out as expected. I'll have track down the issue.

#include <iostream>

class Device
{
public:
    bool deviceState;
    Device *dependent_device;
    Device(Device *in_device) {
        dependent_device = in_device;
        deviceState = true;
        
    }
    void printThis() {
        bool temp = dependent_device->deviceState;
        printf("state: %d \n", temp);
    }
};


int main()
{

    Device *a = new Device(nullptr);
    Device *b = new Device(a);
    b->printThis();
    
    
    
    return 0;
}

I still don't see an actual problem with your original code. If you get '129' and you were expecting something else,
it is possible that the variable that you expected to be 'true' or 'false' wasn't initialized anywhere.

I found the issue. I'm not sure why but declaring it in the base class AND the inherited class made it act funny. I just left it declared in the based class only.