Can't include some libraries inside a class

I was trying to build a class, and when I included the required libraries inside the class, it throws error in case of some libraries while works fine if I comment those particular libraries
What could possibly be wrong?
Any help is appreciated

here’s the code

class Sensors {
  #include "cactus_io_BME280_SPI.h"
  #include <SparkFunTSL2561.h>
  #include <Wire.h>  //  comment this to get it working
  #include <RtcDS3231.h> //  comment this to get it working

 
  private:
    int a,b;
        


  public:
      Sensors(int MoisturePin, int bME_SCK, int bME_MISO, int bME_MOSI, int bME_CS){
      a=10;
      b=12;
       
    }

    


};

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

}

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

}

this is the error message

Arduino: 1.8.12 (Windows Store 1.8.33.0) (Windows 10), Board: "NodeMCU 0.9 (ESP-12 Module), 80 MHz, Flash, Disabled, 4M (no SPIFFS), v2 Lower Memory, Disabled, None, Only Sketch, 115200"

C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.33.0_x86__mdqgnx93n4wtt\arduino-builder -dump-prefs -logger=machine -hardware C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.33.0_x86__mdqgnx93n4wtt\hardware -hardware C:\Users\sadaf\Documents\ArduinoData\packages -tools C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.33.0_x86__mdqgnx93n4wtt\tools-builder -tools -----------------------------------------------------------------------------------------------.................................................................................<

was too long, so had to cut it

                                               ^

C:\Users\sadaf\Documents\Arduino\libraries\Rtc-master\src/RtcDS3231.h:492:49: error: cannot call member function 'uint8_t Sensors::BcdToBin24Hour(uint8_t)' without object

         uint8_t hour = BcdToBin24Hour(raw & 0x7f);

                                                 ^

C:\Users\sadaf\Documents\Arduino\libraries\Rtc-master\src/RtcDS3231.h:496:46: error: cannot call member function 'uint8_t Sensors::BcdToUint8(uint8_t)' without object

         uint8_t dayOf = BcdToUint8(raw & 0x3f);

                                              ^

C:\Users\sadaf\Documents\Arduino\libraries\Rtc-master\src/RtcDS3231.h: In member function 'Sensors::DS3231AlarmTwo Sensors::RtcDS3231<T_WIRE_METHOD>::GetAlarmTwo()':

C:\Users\sadaf\Documents\Arduino\libraries\Rtc-master\src/RtcDS3231.h:520:47: error: cannot call member function 'uint8_t Sensors::BcdToUint8(uint8_t)' without object

         uint8_t minute = BcdToUint8(raw & 0x7F);

                                               ^

C:\Users\sadaf\Documents\Arduino\libraries\Rtc-master\src/RtcDS3231.h:524:49: error: cannot call member function 'uint8_t Sensors::BcdToBin24Hour(uint8_t)' without object

         uint8_t hour = BcdToBin24Hour(raw & 0x7f);

                                                 ^

C:\Users\sadaf\Documents\Arduino\libraries\Rtc-master\src/RtcDS3231.h:528:46: error: cannot call member function 'uint8_t Sensors::BcdToUint8(uint8_t)' without object

         uint8_t dayOf = BcdToUint8(raw & 0x3f);

                                              ^

Using library cactus_io_BME280_SPI in folder: C:\Users\sadaf\Documents\Arduino\libraries\cactus_io_BME280_SPI (legacy)
Using library SparkFun_TSL2561_Arduino_Library-master at version 1.1.0 in folder: C:\Users\sadaf\Documents\Arduino\libraries\SparkFun_TSL2561_Arduino_Library-master 
Using library Wire at version 1.0 in folder: C:\Users\sadaf\Documents\ArduinoData\packages\esp8266\hardware\esp8266\2.5.0\libraries\Wire 
Using library Rtc-master at version 2.3.2 in folder: C:\Users\sadaf\Documents\Arduino\libraries\Rtc-master 
Using library SPI at version 1.0 in folder: C:\Users\sadaf\Documents\ArduinoData\packages\esp8266\hardware\esp8266\2.5.0\libraries\SPI 
exit status 1
uninitialized member 'Sensors::c_daysInMonth' with 'const' type 'const uint8_t [0] {aka const unsigned char [0]}' [-fpermissive]

I'd start by moving all the #include statements outside the class declaration.

,thanks for the reply
but why dosent it work that other way

sabishaw:
,thanks for the reply
but why dosent it work that other way

Because it is a preprocessor directive. Those are executed before compilation proper. An include does what it says, it just makes a text inclusion. So you’d be actually dumping the source code of an entire library into the guts of a class. Surely that is not your intent…

aarg:
Because it is a preprocessor directive. Those are executed before compilation proper. An include does what it says, it just makes a text inclusion. So you'd be actually dumping the source code of an entire library into the guts of a class. Surely that is not your intent...

Thanks aarg, but thats exactly what I want :wink:
I want to create a class which has almost zero coupling, so that I'd be able to copy the whole class if I need it in any other program.
Also, I wonder if i can write some of them in a class, why cant I do the same with others
Thanks tho

NO no no no no…

You are on the wrong path! See the quicksand and rodents of unusual size? Are these not warnings enough?

If you want a car, do you jam the car into your stomach? Do you jam your silverware into your ear? No there are places for these things and in their correct places they will function as you most likely desire.

#include files go at the top. Why? Because its information the stuff below it needs to know how to build itself. Simple as that. There is a slim possibility we could cut you open, jam in a cheeseburger, sew you up and maybe you’d work. Buy why? There is an orifice especially for this.

Now, of you make your class correctly, using the standard way of doing stuff, you can add it to any program by just writing one line : #include “yourClass.h”.

-jim lee

jimLee:
NO no no no no...

You are on the wrong path! See the quicksand and rodents of unusual size? Are these not warnings enough?

If you want a car, do you jam the car into your stomach? Do you jam your silverware into your ear? No there are places for these things and in their correct places they will function as you most likely desire.

#include files go at the top. Why? Because its information the stuff below it needs to know how to build itself. Simple as that. There is a slim possibility we could cut you open, jam in a cheeseburger, sew you up and maybe you'd work. Buy why? There is an orifice especially for this.

Now, of you make your class correctly, using the standard way of doing stuff, you can add it to any program by just writing one line : #include "yourClass.h".

-jim lee

thats hurtful to hear, but thanks ;((

Doesn't hurt as much as the rodent.

-jim lee