Custom class - Identifier is undefined

Hello all,

I am giving VSCode and PlaformIO a try looking for a better coding experience for Arduino. I am having what seems to be some basic difficulty with a custom class.

I have both the .h and the .cpp in the same folder under lib.

My issue is that all of my private variables show as undefined in the cpp file. What is interesting is that if I select one of the undefined variables and press F12, it finds the correct line in the .h file.

Any suggestions on what I am doing wrong?

Thanks
Karl

h file

#ifndef CT_Food_Dispenser_h
#define CT_Food_Dispenser_h

#include <Arduino.h>

class ctFoodDispenser
{

public:
  ctFoodDispenser(int bowlSensorPin, int hopperSensorPinMin, int hopperSensorPinMax, int motorEnablePin, int motorStepPin, int motorDirPin);

  void dispense(int count);

private:
  int _bowlSensorPin;
  int _hopperSensorPinMin;
  int _hopperSensorPinMax;
  int _motorEnablePin;
  int _motorStepPin;
  int _motorDirPin;
};

#endif

CPP File

#include <Arduino.h>
#include "CT_Food_Dispenser.h"

class ctFoodDispenser
{
  ctFoodDispenser(int bowlSensorPin, int hopperSensorPinMin, int hopperSensorPinMax, int motorEnablePin, int motorStepPin, int motorDirPin)
  {
    _motorEnablePin = motorEnablePin; 
    _motorStepPin = motorStepPin;
    _bowlSensorPin = 1;
  };

  void dispense(int count){
  };
};

Screenshot 2021-07-07 201823

Read through tutorials like this to see how you need to write the implementation of a class in a .cpp file in C++. What you are doing here is redeclare a class of the same name as in the .h file, but without all the private variables, thus getting that error. However, the solution is not to add those in, as the link and other C++ learning resources show, you need to write in a different fashion.

#include <Arduino.h>
#include "CT_Food_Dispenser.h"

ctFoodDispenser::ctFoodDispenser(int bowlSensorPin, int hopperSensorPinMin, int hopperSensorPinMax, int motorEnablePin, int motorStepPin, int motorDirPin)
{
    _motorEnablePin = motorEnablePin; 
    _motorStepPin = motorStepPin;
    _bowlSensorPin = 1;
}

void ctFoodDispenser::dispense(int count){

}

Also note that the above implementation logic is the same as in yours, which does not save the constructor parameters bowlSensorPin, hopperSensorPinMin/Max and motorDirPin into the internal member variables.

I thought it was something simple I was not seeing. Thank you!