Help with ERROR: Request for member ABC in XYZ, which is of non-class type 123

Hi,

Am getting the error message;
request for member 'getTemp' in 'shed_temp', which is of non-class type 'TSensor()
when validating my sketch.

I've searched for hours and tried all the suggestions for others with this error.

Can you please assist and most importantly telling me why it's not working (I'm using this example to break up working code into objects/classes as a learning experience).

Thanks in advance.

BreweryTemp_v2.zip (3.81 KB)

Please post the full error message

If you post your code and the entire error message as described in the how to use this forum guidelines more members will see it and you will get help faster. Most members will not download zip files.

Thank you for the prompt Guidance. Below is the full error message, the main .ino code and I've attached the libraries referenced (.cpp and .h files)

Here is the full error message string.

Arduino: 1.8.12 (Windows Store 1.8.33.0) (Windows 10), Board: "Arduino/Genuino Uno"

C:\Users\Cameron\OneDrive\Documents\Arduino\BreweryTemp_v2\BreweryTemp_v2.ino:25:18: warning: character constant too long for its type

   Serial.println('Clock: ' + time_str.text);

                  ^~~~~~~~~

sketch\Led.cpp:16:48: warning: default argument given for parameter 1 of 'void Led::blink(byte, int)' [-fpermissive]

 void Led::blink(byte number = 1, int time = 250) {

                                                ^

In file included from sketch\Led.cpp:1:0:

sketch\Led.h:12:10: note: previous specification in 'void Led::blink(byte, int)' here

     void blink(byte number = 1, int time = 250);

          ^~~~~

sketch\Led.cpp:16:48: warning: default argument given for parameter 2 of 'void Led::blink(byte, int)' [-fpermissive]

 void Led::blink(byte number = 1, int time = 250) {

                                                ^

In file included from sketch\Led.cpp:1:0:

sketch\Led.h:12:10: note: previous specification in 'void Led::blink(byte, int)' here

     void blink(byte number = 1, int time = 250);

          ^~~~~

sketch\Cooler.cpp:2:46: warning: default argument given for parameter 2 of 'Cooler::Cooler(byte, bool)' [-fpermissive]

 Cooler::Cooler(byte pin, bool relay_NO = true) {      // no is normally open, to specify the default behaviour of the relay

                                              ^

In file included from sketch\Cooler.cpp:1:0:

sketch\Cooler.h:9:5: note: previous specification in 'Cooler::Cooler(byte, bool)' here

     Cooler(byte pin, bool relay_NO = true);        // no is normally open, to specify the default behaviour of the relay

     ^~~~~~

C:\Users\Cameron\OneDrive\Documents\Arduino\BreweryTemp_v2\BreweryTemp_v2.ino: In function 'void setup()':

C:\Users\Cameron\OneDrive\Documents\Arduino\BreweryTemp_v2\BreweryTemp_v2.ino:33:41: warning: invalid conversion from 'const uint8_t* {aka const unsigned char*}' to 'uint8_t* {aka unsigned char*}' [-fpermissive]

   TSensor shed_temp(DS_SHED, sensors, 20);

                                         ^

In file included from C:\Users\Cameron\OneDrive\Documents\Arduino\BreweryTemp_v2\BreweryTemp_v2.ino:3:0:

sketch\TSensor.h:10:5: note:   initializing argument 1 of 'TSensor::TSensor(uint8_t*, DallasTemperature, float)'

     TSensor(uint8_t device_address[8], DallasTemperature sensors, float start_temp = 18);

     ^~~~~~~

C:\Users\Cameron\OneDrive\Documents\Arduino\BreweryTemp_v2\BreweryTemp_v2.ino:34:47: warning: invalid conversion from 'const uint8_t* {aka const unsigned char*}' to 'uint8_t* {aka unsigned char*}' [-fpermissive]

   TSensor outside_temp(DS_OUTSIDE, sensors, 20);

                                               ^

In file included from C:\Users\Cameron\OneDrive\Documents\Arduino\BreweryTemp_v2\BreweryTemp_v2.ino:3:0:

sketch\TSensor.h:10:5: note:   initializing argument 1 of 'TSensor::TSensor(uint8_t*, DallasTemperature, float)'

     TSensor(uint8_t device_address[8], DallasTemperature sensors, float start_temp = 18);

     ^~~~~~~

C:\Users\Cameron\OneDrive\Documents\Arduino\BreweryTemp_v2\BreweryTemp_v2.ino: In function 'void loop()':

BreweryTemp_v2:44:13: error: request for member 'getTemp' in 'shed_temp', which is of non-class type 'TSensor()'

   shed_temp.getTemp();

             ^~~~~~~

BreweryTemp_v2:45:16: error: request for member 'getTemp' in 'outside_temp', which is of non-class type 'TSensor()'

   outside_temp.getTemp;

                ^~~~~~~

BreweryTemp_v2:55:26: error: request for member 'last_temp' in 'shed_temp', which is of non-class type 'TSensor()'

   Serial.print(shed_temp.last_temp);

                          ^~~~~~~~~

BreweryTemp_v2:59:29: error: request for member 'last_temp' in 'outside_temp', which is of non-class type 'TSensor()'

   Serial.print(outside_temp.last_temp);

                             ^~~~~~~~~

BreweryTemp_v2:62:17: error: request for member 'last_temp' in 'shed_temp', which is of non-class type 'TSensor()'

   if (shed_temp.last_temp > 14) {

                 ^~~~~~~~~

BreweryTemp_v2:63:19: error: request for member 'last_temp' in 'shed_temp', which is of non-class type 'TSensor()'

     if (shed_temp.last_temp > outside_temp.last_temp) {

                   ^~~~~~~~~

BreweryTemp_v2:63:44: error: request for member 'last_temp' in 'outside_temp', which is of non-class type 'TSensor()'

     if (shed_temp.last_temp > outside_temp.last_temp) {

                                            ^~~~~~~~~

BreweryTemp_v2:66:7: error: expected ';' before '}' token

       }

       ^

sketch\TSensor.cpp:3:93: warning: default argument given for parameter 3 of 'TSensor::TSensor(uint8_t*, DallasTemperature, float)' [-fpermissive]

 TSensor::TSensor(uint8_t device_address[8], DallasTemperature sensors, float start_temp = 18) {

                                                                                             ^

In file included from sketch\TSensor.cpp:1:0:

sketch\TSensor.h:10:5: note: previous specification in 'TSensor::TSensor(uint8_t*, DallasTemperature, float)' here

     TSensor(uint8_t device_address[8], DallasTemperature sensors, float start_temp = 18);

     ^~~~~~~

sketch\Timelag.cpp: In member function 'void Timelag::init()':

sketch\Timelag.cpp:8:31: warning: integer overflow in expression [-Woverflow]

   byte days = trunc(tmp/(24*60*60*1000));

                          ~~~~~^~~

sketch\Timelag.cpp:10:32: warning: integer overflow in expression [-Woverflow]

   byte hours = trunc(tmp/(60*60*1000));

                           ~~~~~^~~~~

sketch\Timelag.cpp:12:28: warning: integer overflow in expression [-Woverflow]

   byte mins = trunc(tmp/(60*1000));

                          ~~^~~~~

sketch\TSensor.cpp: In member function 'void TSensor::getTemp()':

sketch\TSensor.cpp:36:21: warning: invalid conversion from 'const char*' to 'char' [-fpermissive]

     last_result[8]= "OK";

                     ^~~~

exit status 1
request for member 'getTemp' in 'shed_temp', which is of non-class type 'TSensor()'

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Here is the main programme code (.ino)

#include "Led.h"
#include "Cooler.h"
#include "TSensor.h"
#include "Timelag.h"
#include <OneWire.h>              // To access any one wire based sensors
#include <DallasTemperature.h>    // For temperature functions and conversions on the DS18B20 specifically

bool ErrorLED = false;
Led green_led(8);
Led red_led(9);
Led error_led(12);
Cooler shed_fan(11);

OneWire oneWire(10);               // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
DallasTemperature sensors(&oneWire);    // Pass our oneWire reference to Dallas Temperature. 
TSensor shed_temp(void);
TSensor outside_temp(void);

void setup() {
  // put your setup code here, to run once:

  // start serial port for output to console/terminal
  Serial.begin(9600);
  Timelag time_str = Timelag(millis());
  Serial.println('Clock: ' + time_str.text); 
  Serial.println("Welcome to OBSession Brewery!"); 
  Serial.println("");

  sensors.begin();
  const uint8_t DS_SHED[8] = { 0x28, 0x13, 0x16, 0x94, 0x97, 0x10, 0x03, 0x4F };
  const uint8_t DS_OUTSIDE[8] = { 0x28, 0x79, 0x4C, 0x94, 0x97, 0x09, 0x03, 0x35 };
  // const uint8_t DS_BB[8] = { 0x28, 0x26, 0x3B, 0x22, 0x0B, 0x00, 0x00, 0x58 };
  TSensor shed_temp(DS_SHED, sensors, 20);
  TSensor outside_temp(DS_OUTSIDE, sensors, 20);
  shed_temp.getTemp();
  outside_temp.getTemp();

}

void loop() {
  // put your main code here, to run repeatedly:

  // Calculate the Temperatures
  shed_temp.getTemp();
  outside_temp.getTemp;

  // Turn on the ErrorLED if in an error state
  if (ErrorLED) { error_led.on(); }
  else { error_led.off(); }
  // Need to put checks in all the critical spaces to check for errors and update this flag

  // CONTROL THE FAN
  Serial.print(millis());
  Serial.print(" | Shed(C): ");
  Serial.print(shed_temp.last_temp);
  //Serial.print(" | Target(C): ");
  //Serial.print(TEMPSHEDTARGET);
  Serial.print(" | Outside(C): ");
  Serial.print(outside_temp.last_temp);
  Serial.print(" | ");

  if (shed_temp.last_temp > 14) {
    if (shed_temp.last_temp > outside_temp.last_temp) {
      shed_fan.on();
      delay(300000)
      }
    else { shed_fan.off(); }
  }
  else { shed_fan.off(); }

  delay(60000);                                // Wait 1 Minute
  
}

Cooler.cpp (484 Bytes)

Cooler.h (290 Bytes)

Led.cpp (388 Bytes)

Led.h (208 Bytes)

Timelag.cpp (506 Bytes)

Timelag.h (232 Bytes)

TSensor.cpp (1.3 KB)

TSensor.h (387 Bytes)

Hi,

I have "solved" this by moving the instantiation of the object into the global scope and repeating it again in the setup() routine once sensors.begin() function has been executed.

This doesn't feel right to me, but it works. I would still appreciate input on what the correct way to address this need is. (I need the objects to be in global scope but can't properly create them until the sensors.begin function has executed which I can't do in the global scope). There doesn't seem to be a global keyword in the Arduino reference guide that would allow me to do this within the setup function.

Thanks.

Here is the working version of the code;

#include "Led.h"
#include "Cooler.h"
#include "TSensor.h"
#include "Timelag.h"
#include <OneWire.h>              // To access any one wire based sensors
#include <DallasTemperature.h>    // For temperature functions and conversions on the DS18B20 specifically

bool ErrorLED = false;
Led green_led(8);
Led red_led(9);
Led error_led(12);
Cooler shed_fan(11);

OneWire oneWire(10);               // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
DallasTemperature sensors(&oneWire);    // Pass our oneWire reference to Dallas Temperature. 
uint8_t DS_SHED[8] = { 0x28, 0x13, 0x16, 0x94, 0x97, 0x10, 0x03, 0x4F };
uint8_t DS_OUTSIDE[8] = { 0x28, 0x79, 0x4C, 0x94, 0x97, 0x09, 0x03, 0x35 };
// uint8_t DS_BB[8] = { 0x28, 0x26, 0x3B, 0x22, 0x0B, 0x00, 0x00, 0x58 };
TSensor shed_temp(DS_SHED, sensors, 20);            //Redefine in the setup() routine after sensors.begin has happened
TSensor outside_temp(DS_OUTSIDE, sensors, 20);      //Redefine in the setup() routine after sensors.begin has happened

void setup() {
  // put your setup code here, to run once:

  // start serial port for output to console/terminal
  Serial.begin(9600);
  Timelag time_str = Timelag(millis());
  Serial.println("Clock: " + time_str.text); 
  Serial.println("Welcome to OBSession Brewery!"); 
  Serial.println("");

  sensors.begin();
  TSensor shed_temp(DS_SHED, sensors, 20);          //Redfining after sensor.begin() which I couldn't excute before the setup() but couldn't declare the objects globally without doing this.
  TSensor outside_temp(DS_OUTSIDE, sensors, 20);    //Redfining after sensor.begin() which I couldn't excute before the setup() but couldn't declare the objects globally without doing this.
  shed_temp.getTemp();
  outside_temp.getTemp();

}

void loop() {
  // put your main code here, to run repeatedly:

  // Calculate the Temperatures
  shed_temp.getTemp();
  outside_temp.getTemp();

  // Turn on the ErrorLED if in an error state
  if (ErrorLED) { error_led.on(); }
  else { error_led.off(); }
  // Need to put checks in all the critical spaces to check for errors and update this flag

  // CONTROL THE FAN
  Serial.print(millis());
  Serial.print(" | Shed(C): ");
  Serial.print(shed_temp.last_temp);
  //Serial.print(" | Target(C): ");
  //Serial.print(TEMPSHEDTARGET);
  Serial.print(" | Outside(C): ");
  Serial.print(outside_temp.last_temp);
  Serial.print(" | ");

  if (shed_temp.last_temp > 14) {
    if (shed_temp.last_temp > outside_temp.last_temp) {
      shed_fan.on();
      delay(300000);                // Wait 5 mins if you have to turn the fan on
      }
    else { shed_fan.off(); }
  }
  else { shed_fan.off(); }

  delay(60000);                                // Wait 1 Minute
  
}

That’s definitely wrong. The second set of Tsensor definitions are local to setup(). They cease to exist after that function exits.

The problem is in the code you haven’t posted. However, I’m not going to download 8 separate files and piece your project together. If you’ll make a simple Minimal Reproducible Example that demonstrates the problem and can be posted for easy copy / paste into the Arduino IDE, you’d stand a much better chance of getting more help.