Learner - error the constructor is undefined.
in
Programming Questions
•
9 months ago
Hey, Im currently doing a class exercise on classes and objects and so my program is very basic, however, i am getting the error message the constructor xx(string, int, float) is undefined.
Here is my code, please help me work out why there is an error.
StockItem s1, s2;
void setup() {
s1 = new StockItem();
s2 = new StockItem("Apple", 5, 17.50);
s1.display();
s2.display();
}
class StockItem {
string title;
int quantityLeft;
float unitPrice;
StockItem() {
title = "Cocaine";
quantityLeft = 300;
unitPrice = 10000;
}
StockItem(string t, int qL, float uP) {
title = t;
quantityLeft = sqrt(qL^2);
unitPrice = sqrt(uP^2);
}
void display() {
printLn(title + quantityLeft + unitPrice);
}
}
1