Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty constructor fails, I don't understand why #53

Open
DaleSchultz opened this issue Jan 19, 2023 · 0 comments
Open

Empty constructor fails, I don't understand why #53

DaleSchultz opened this issue Jan 19, 2023 · 0 comments

Comments

@DaleSchultz
Copy link

SimpleDH11 defines two public constructors:

    SimpleDHT11();
    SimpleDHT11(int pin);

and they are implemented like this:

SimpleDHT11::SimpleDHT11() {
}
SimpleDHT11::SimpleDHT11(int pin) : SimpleDHT (pin) {
}

Which all looks perfectly fine. If, however, we declare an object of type SimpleDHT11 without a pin, the sketch fails to compile.

Here is a minimal sketch to show it.

#include <SimpleDHT.h>

int pinDHT11 = 14;

SimpleDHT11 dht11(); // fails, error: request for member 'read2' in 'dht11', which is of non-class type 'SimpleDHT11()'
//SimpleDHT11 dht11(-1); //works fine

void setup() {
  Serial.begin(115200);
}

void loop(){
  float temperature = 0;
  float humidity = 0;
  int err = dht11.read2( pinDHT11, &temperature, &humidity, NULL);
  Serial.println(humidity);
  delay(1200);
}

If we pass in a dummy pin number, such as -1, the code compiles and works. I pass in the pin number to the read/read2 function which are all overloaded to include, or not include, the pin.

Because of the design of my application, I wish to be able to specify the pin on each call to read, so my plan was to not specify a pin in the constructor call. I have no problem passing in a dummy value, but I am trying to understand why it does not work without.

This is happening on a Wemos D1 (ESP8266), Arduino IDE 2.0.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant