class PlantClass{
private: //public otherwise error: test::test private
float pH;
int plant_pos;
String plant_type;
public:
PlantClass(){ //the constructor
pH=-1;
plant_pos=-1;
plant_type="-1";
}
PlantClass(float temppH, int tempPlantPos,String tempType)//Overloaded constructor
{
pH=temppH;
plant_pos=tempPlantPos;
plant_type=tempType;
}
void setpH(float temp){pH=temp;}
float getpH(){return pH;}
void setPlantPos(int temp) {plant_pos=temp;}
int getPlantPos(){return plant_pos;}
void setPlantType(String temp){plant_type=temp;}
};
#include <Wprogram.h>
//Relay board 1
const int pump_pin= 0;
const int water_recirc= 1;
const int light_assm_1= 2;
const int light_assm_2= 3;
const int heater= 4;
const int inj_food= 5;
const int inj_ph_m= 6;
const int inj_ph_p= 7;
//Relay board 2
const int inj_p1= 8;
const int inj_p2= 9;
const int inj_p3= 10;
const int inj_p4= 11;
PlantClass test_array[4];
PlantClass p1=PlantClass();
PlantClass p2= PlantClass(5.5,0,"Test");
test_array[0]=PlantClass();
void setup()
{
Serial.begin(9600);
pinMode(pump_pin,OUTPUT);
pinMode(water_recirc,OUTPUT);
pinMode(light_assm_1,OUTPUT);
pinMode(light_assm_2,OUTPUT);
pinMode(heater,OUTPUT);
pinMode(inj_food,OUTPUT);
pinMode(inj_ph_m,OUTPUT);
pinMode(inj_ph_p,OUTPUT);
pinMode(inj_p1,OUTPUT);
pinMode(inj_p2,OUTPUT);
pinMode(inj_p3,OUTPUT);
pinMode(inj_p4,OUTPUT);
}
void loop()
{
}
PlantClass p1=PlantClass();
PlantClass p2= PlantClass(5.5,0,“Test”);
Both work
Why does “test_array[0]=PlantClass();” not work?
functional:48: error: expected constructor, destructor, or type conversion before ‘=’ token