I am a beginner and writing a program for fun that helps me diet. This program isn’t done but compiling as I write. I keep getting the error mentioned in the title:
Undefined symbols for architecture x86_64 with classes
I’ve looked at similar questions but they all have to do with templates and inherited classes which is different than my scenario. I’m just declaring a class, nothing fancy. I think it has to do with the class not being defined properly but I can’t figure out what it is. It might be something dumb I’m missing but I’m still stuck. Thanks.
#include <iostream>
#include <string>
using namespace std;
class Meal
{
private:
string name;
int protein;
int carbs;
int fat;
int calories;
public:
Meal(string name, int calories, int protein, int carbs, int fat);
};
int main()
{
int calories = 0;
int rest_or_lift;
int create_or_not;
cout << "Enter 1 if it is a workout day, enter 2 if it is a rest day./n";
cin >> rest_or_lift;
if (rest_or_lift == 1)
{
calories = 2554;
}
else if (rest_or_lift == 2)
{
calories = 1703;
}
cout << "Enter 1 to input existing foods, enter 2 to create new foods./n";
cin >> create_or_not;
if (create_or_not == 1)
{
cout << "This aspect has not yet been created /n"; //need to fix this part
}
else if (create_or_not == 2)
{
do
{
string name;
int protein;
int carbs;
int fat;
int calories;
cout << "Enter the name of the food./n";
cin >> name;
cout << "Enter how many calories the food has. /n";
cin >> calories;
cout << "Enter how many grams of protein the food has /n";
cin >> protein;
cout << "Enter how many grams of carbs the food has /n";
cin >> carbs;
cout << "Enter how many grams of fats the food has /n";
cin >> fat;
Meal(name, calories, protein, carbs, fat);
cout << "Enter another food? Enter 1 to exit, 2 to continue.";
cin >> create_or_not;
} while (create_or_not == 2);
}
return 0;
}
There is no constructor for class
Meal. You can solve it e.g. like this: