I am learning OOP in C++, and I am writing the most basic class. I am having a problem with declaring an object for the class. I getting the error posted in the title. I know my class works because I put the class in “main.cpp”, and I could declare an object no problem. Why is this happening? How can I fix it?
My code
Food.h
#ifndef PORJECT2_FOOD_H
#define PORJECT2_FOOD_H
const char* RecommendFood(char firstLetter);
class Foods;
#endif //PORJECT2_FOOD_H
Food.cpp
#include "Food.h"
#include <String>
using namespace std;
class Foods{
public:
string name;
int qty;
const string &getName() const {
return name;
}
void setName(const string &name) {
Foods::name = name;
}
int getQty() const {
return qty;
}
void setQty(int qty) {
Foods::qty = qty;
}
};
main.cpp
Foods obj;
string food1 = "Fruit", food2 = "Veggies", Food1, Food2;
int qty1 = 15, qty2 = 165, QTY1, QTY2;
obj.setName(food1);
obj.setQty(qty1);
Food1 = obj.getName();
QTY1 = obj.getQty();
cout << "Food: " << Food1 << " Qty: " << QTY1 << "n";
obj.setName(food2);
obj.setQty(qty2);
Food2 = obj.getName();
QTY2 = obj.getQty();
cout << "Food: " << Food2 << " Qty: " << QTY2 << "n";
return 0;
}