错误:带有类的体系结构x86_64的未定义符号

时间:2012-11-22 09:05:51

标签: c++

我是一名初学者,正在编写一个有趣的程序,可以帮助我减肥。这个程序没有完成,只是在编写时进行编译。我一直收到标题中提到的错误:

  

具有类

的体系结构x86_64的未定义符号

我看过类似的问题,但它们都与模板和继承的类有关,这与我的场景不同。我只是宣布一堂课,没什么特别的。我认为它与未被正确定义的类有关,但我无法弄清楚它是什么。这可能是我失踪的愚蠢但我仍然被卡住了。感谢。

#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;
}

1 个答案:

答案 0 :(得分:3)

Meal没有构造函数。你可以解决它,例如像这样:

class Meal
{
private:
  string m_name;
  int m_protein;
  int m_carbs;
  int m_fat;
  int m_calories;

public:
  Meal(string name, int calories, int protein, int carbs, int fat)
    : m_name(name), m_protein(protein),
      m_carbs(carbs), m_fat(fat), m_calories(calories)
  {
  }
};