Getting error cannot call member function


#1

Now that I included particle.h I have landed into new problem:

this is the header file:

namespace DustSensor {
    class DustSensor_Reader
    {
     public:
     // returns bool 
     bool pms7003_read();
        
    };
    }

and the dustSensor.cpp file contains:

#include "dustSensor.h"
#include "Particle.h"

....

const bool DEBUG = false;


uint16_t calcChecksum = 0;

namespace DustSensor {
 
bool pms7003_read() {
    //  Particle.publish("PMS7003", printbuf, 60, PRIVATE);
    // send data only when you receive data:
    Serial.println("-- Reading PMS7003");
    Serial1.begin(9600);
    bool packetReceived = false;
  .
  .
  .
}
}

in my ino file I have added include <dustSensor.h>
then where later I need to access the function form dustSensor.cpp I call it like this:
bool dust = DustSensor::DustSensor_Reader::pms7003_read();

but this is throwing error:
cannot call member function 'bool DustSensor::DustSensor_Reader::pms7003_read()' without object

please help…


Getting error 'Serial' was not declared in this scope
#2

In order to call the function like this, without an object:

bool dust = DustSensor::DustSensor_Reader::pms7003_read();

the member function must be declared static:

namespace DustSensor {
    class DustSensor_Reader
    {
     public:
     // returns bool 
     static bool pms7003_read();
        
    };
    }

Only in the declaration, not the implementation.

Though the implementation should probably be:

namespace DustSensor {
 
bool DustSensor_Reader::pms7003_read() {
    //  Particle.publish("PMS7003", printbuf, 60, PRIVATE);
    // send data only when you receive data:
    Serial.println("-- Reading PMS7003");
    Serial1.begin(9600);
    bool packetReceived = false;
  .
  .
  .
}
}

#3

thanks, all works now, can you please share link me up cpp docs I can read and learn while I code !