expected unqualified-id

hello,
for some reason, I can't get the call to the parent's constructor...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
DHTesp.h:
class DHTesp
{
public:

...
  void setup(uint8_t dhtPin) __attribute__((deprecated));
  void setup(uint8_t pin, DHT_MODEL_t model=AUTO_DETECT);
...
}

Sensor_DHT.h:
#include "DHTesp.h"

class DHT : public DHTesp{
...
public:
	DHT(int pin, EventGroupHandle_t evgrp, int time_bit, const char* TaskName, TickType_t cycle_ms = 10000 );
...
}

Sensor_DHT.cpp:
...
DHT::DHT(int pin, EventGroupHandle_t evgrp, int event_bit, const char* TaskName, TickType_t cycle_ms ) {
	DHTesp.setup(pin,DHTesp::DHT11) ;
...


I tried to :
1
2
DHT::DHT(int pin, EventGroupHandle_t evgrp, int event_bit, const char* TaskName, TickType_t cycle_ms ):  DHTesp.setup(pin,DHTesp::DHT11) { ... }


But the compilation fails with :

src/Sensor_DHT.cpp: In constructor 'DHT::DHT(int, EventGroupHandle_t, int, const char*, TickType_t)':
src/Sensor_DHT.cpp:29:8: error: expected unqualified-id before '.' token

I appreciate your input.
Last edited on
Constructor? You are trying to call a member function, not a constructor.
Looks like you're trying to write the implementation of this constructor?
DHT::DHT(int pin, EventGroupHandle_t evgrp, int event_bit, const char* TaskName, TickType_t cycle_ms )

Looks like you want the constructor to call a class member function, setup.

1
2
3
4
DHT::DHT(int pin, EventGroupHandle_t evgrp, int event_bit, const char* TaskName, TickType_t cycle_ms )
{
   setup(pin,DHTesp::DHT11);
}

oh... right. "setup" is not a constructor... Thank you for pointing out that!

DHT class doesn't seem to have a constructor. in the example, they go by :
1
2
3
4
5
...
DHTesp dht;
...
dht.setup(...);
...


what is the line of thinking when creating a class without specifying a constructor?

Thank you !
what is the line of thinking when creating a class without specifying a constructor?

The line of thinking is "I want to create an object and the constructor doesn't need any parameters, I can just use the default constructor". It's pretty normal and common.


It is bad object, bad C++, to have a class that needs the programmer to call an extra member function on it just to put it into a good state. If that member function MUST always be called, that it should be called in the constructor.


DHT class doesn't seem to have a constructor.

This is a constructor:
DHT(int pin, EventGroupHandle_t evgrp, int time_bit, const char* TaskName, TickType_t cycle_ms = 10000 );


Edit: Oh, you've edited the original post and changed your original question, rendering the answers nonsensical. Please don't do that. It renders the thread nonsensical.


Now you're just calling the function wrong.
1
2
DHT::DHT(int pin, EventGroupHandle_t evgrp, int event_bit, const char* TaskName, TickType_t cycle_ms ) {
	DHTesp.setup(pin,DHTesp::DHT11) ;  // This is NOT how to call a member function. 


I already wrote the code that showed you how to call a member funciton. I already wrote the code that calls the setup function inside the constructor. What happens if, instead of doing it wrong, you write the code as I showed you?
Last edited on
Repeater,
thank you very much. _all_ your questions make perfect sense to me. If I did mess up the original post - my apologies. But as of right now - all answers make perfect sense to me.

I see now, that my copy from example ("dht") and copy from my code ("DHT") possibly create confusion.

... I already wrote the code that showed you how to call a member function. I already wrote the code that calls the setup function inside the constructor. What happens if, instead of doing it wrong, you write the code as I showed you?


it got happily compiled :)
Topic archived. No new replies allowed.