The code does not compile. I do not understand what the error is, help please)
#include <iostream>
#include <fstream>
class Record{
std::string product_name;
std::string product_category;
int price;
int amount;
public:
Record(std::string newName, std::string newCategory, int newPrice, int newAmount){
product_name=newName;
product_category=newCategory;
price=newPrice;
amount=newAmount;
}
std::string getName(){
return product_name;
}
std::string getCategory(){
return product_category;
}
int getPrice(){
return price;
}
int getAmount(){
return amount;
}
void setName(std::string newName){
product_name=newName;
}
void setCategory(std::string newCategory){
product_category=newCategory;
}
void setPrice(int newPrice){
price=newPrice;
}
void setAmount(int newAmount){
amount=newAmount;
}
};
int main(){
Record r1;
r1.setName("beer");
r1.setCategory("alcohol");
r1.setPrice(12);
r1.setAmount(32);
Record r2("carrot", "vegetables", 123, 1932);
std::cout<<r1.getName()<<" "<<r1.getCategory()<<" "<<r1.getPrice()<<" "<<r1.getAmount()<< std::endl;
std::cout<<r2.getName()<<" "<<r2.getCategory()<<" "<<r2.getPrice()<<" "<<r2.getAmount()<< std::endl;
Record r3[2];
std::string a;
float b;
unsigned int c;
for(unsigned int i=0; i<2; ++i){
std::cout<<"input name: ";
std::cin>>a;
r3[i].setName(a);
std::cout<<"input category: ";
std::cin>>a;
r3[i].setCategory(a);
std::cout<<"input price: ";
std::cin>>b;
r3[i].setPrice(b);
std::cout<<"input amount: ";
std::cin>>c;
r3[i].setAmount(c);
}
for(unsigned int i=0; i<2; ++i){
std::cout<<r3[i].getName()<<" "<<r3[i].getCategory()<<" "<<r3[i].getPrice()<<" "<<r3[i].getAmount()<< std::endl;
}
return 0;
}
Error text: g++ -Wall -c "main.cpp" ( /media/ad/4GB-NTFS/prog/laba2) main.cpp: In function ‘int main()’: main.cpp:46:12: error: no matching function for call to ‘Record::Record()’ Record r1; ^ main.cpp:12:1: note: candidate: Record::Record(std::__cxx11::string, std::__cxx11::string, int, int) Record(std::string newName, std::string newCategory, int newPrice, int newAmount){ ^ main.cpp:12:1: note: candidate expects 4 arguments, 0 provided main.cpp:6:7: note: candidate: Record::Record(const Record&) class Record{ ^ main.cpp:6:7: note: candidate expects 1 argument, 0 provided main.cpp:54:16: error: no matching function for call to ‘Record::Record()’ Record r3[2]; ^ main.cpp:12:1: note: candidate: Record::Record(std::__cxx11::string, std::__cxx11::string, int, int) Record(std::string newName, std::string newCategory, int newPrice, int newAmount){ ^ main.cpp:12:1: note: candidate expects 4 arguments, 0 provided main.cpp:6:7: note: candidate: Record::Record(const Record&) class Record{ ^ main.cpp:6:7: note: candidate expects 1 argument, 0 provided
no matching function for call to ‘Record::Record()‘
– Drew Dormann