0

I am getting this error message repeatedly and I do not know why. I have tried looking online and have found that this error message comes from the linker, not the compiler, and it is trying to tell me that I have not linked against the library or object code. Maybe I'm missing a variable? I don't know.

Here is the code:

class foodType
{
public:
    void set(string, int, double, int, double, double);
    void print() const;
    foodType(string = "", int = 0, double = 0.0, int = 0, double = 0.0, double = 0.0);
    
private:
    string name;
    int calories;
    double fat;
    int sugar;
    double carbohydrate;
    double potassium;
};

foodType apple;

int main()
{
    apple.set( "Apple" , 100, 0.10, 10, 100.00, 0.02);
    apple.print();

    return 0;
}

void foodType::set(string fruitName, int Cal, double fats,
                        int sug, double carbs, double K)
{
    name = fruitName;
    calories = Cal;
    fat = fats;
    sugar = sug;
    carbohydrate = carbs;
    potassium = K;
}

void foodType::print() const
{
    cout << "Fruit is: "        << name << endl;
    cout << "Calories: "        << calories << endl;
    cout << "Fat content: "     << fat << endl;
    cout << "Sugar content: "   << sugar << endl;
    cout << "Carbs: "           << carbohydrate << endl;
    cout << "Potassium: "       << potassium << endl;
}
  • What is the symbol for the error message? That's important. – Tumbleweed53 Dec 30 '20 at 16:58
  • How are you compiling the code? – Nathan Pierson Dec 30 '20 at 16:59
  • Is there a definition of the `foodType` constructor anywhere? Right now all I see is its declaration. – Nathan Pierson Dec 30 '20 at 17:00
  • The symbol is: Undefined symbol: foodType::foodType(std::__1::basic_string, std::__1::allocator >, int, double, int, double, double) The code does not compile. I am using Xcode as my IDE. I am confused about what you mean by definition. I am looking through my review book to see if I can find that. I thought the constructor I had was the declaration and definition. – programmer_noob Dec 30 '20 at 19:18

1 Answers1

4

You are missing a definition for foodType::foodType.

Tumbleweed53
  • 1,491
  • 7
  • 13
  • Okay! I got it to work. I needed to add two curly braces to the end of my constructor. it now looks like this: ``` foodType(string = "", int = 0, double = 0.0, int = 0, double = 0.0, double = 0.0) {}; ``` Thanks for your help – programmer_noob Dec 30 '20 at 19:21