1
votes

Title says all. The error is

Error 1 error LNK2019: unresolved external symbol "private: void __thiscall Salsa::getTotal(void)" (?getTotal@Salsa@@AAEXXZ) referenced in function "public: void __thiscall Salsa::getSold(void)" (?getSold@Salsa@@QAEXXZ)

Error 2 error LNK2019: unresolved external symbol "private: void __thiscall Salsa::getHigh(void)" (?getHigh@Salsa@@AAEXXZ) referenced in function "public: void __thiscall Salsa::getSold(void)" (?getSold@Salsa@@QAEXXZ)

Error 3 error LNK2019: unresolved external symbol "private: void __thiscall Salsa::getLow(void)" (?getLow@Salsa@@AAEXXZ) referenced in function "public: void __thiscall Salsa::getSold(void)" (?getSold@Salsa@@QAEXXZ)

Error 4 error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup Chips And Salsa Class

The code is as follows; .h file, then .cpp;

#ifndef SALSA_H
#define SALSA_H

class Salsa
{
private:
    void getTotal();
    void getHigh();
    void getLow();
    int count;
    int total;
    int highest;
    int lowest;
    int flavor;
public:
    void getSold();
};
#endif

And now the .cpp;

#include "Salsa.h"
#include <iostream>
#include <string>
using namespace std;


void Salsa::getSold()
{
    for (count = 0; count < 5; count++)
    {
        cout << "Jar sold last month of ";
        cout << count + 1;
        cin >> flavor;

        while (flavor <= 0)
        {
            cout << "Jars sold must be greater than or equal to 0.";
            cout << "Re-enter jars sold for last month ";
            cin >> flavor;
            cout << endl;


        }
        Salsa::getTotal();
        Salsa::getHigh();
        Salsa::getLow();
    }

    Salsa::getTotal();

    total = 0;

    for (count = 0; count < 5; count++)
    {
        total += flavor;

        cout << "Total Sales: " << total << endl;
    }

    Salsa::getHigh();
    {
        highest = flavor;
        int index = 1;

        for (count = 0; count < 5; count++)
            if (flavor > highest)
            {
            highest = flavor;
            index = count + 1;
            }

        cout << "High Seller: " << flavor << endl;
    }

    Salsa::getLow();
    {
        lowest = flavor;
        int index = 1;

        for (count = 0; count < 5; count++)
        {
            if (flavor < lowest)
            {
                lowest = flavor;
                index = count + 1;
            }

            cout << "Low Seller: " << flavor << endl;
        }

        int main();
        {
            const int SALS_FLAV = 5;
            string flavor[SALS_FLAV] = { "mild", "medium", "sweet", "hot", "zesty" };

            Salsa sold;

            for (int index = 0; index < SALS_FLAV; index++)
            {
                sold.getSold();
            }
        }
    }
}
1
Every method definition except Salsa::getSold seems to be inside that method. Thus none of the other methods has been defined.tsnorri
@tsnorri In the .h or .cpp file? Because it's in both, public for the .h, and near the top for the .cpp... Unless I'm completely misunderstanding you?3ncrypt3d
@BaummitAugen the author of that thread never even considered this possibility..:)M.M

1 Answers

3
votes

There are many issues with your code:

  1. You did not declare the return type of your functions
  2. You should not end the function definition with a ;
  3. You did not take care in closing your functions properly, now they become nested functions

Please study the differences between your code and the below code:

#include "Salsa.h"
#include <iostream>
#include <string>
using namespace std;


void Salsa::getSold()
{
    for (count = 0; count < 5; count++)
    {
        cout << "Jar sold last month of ";
        cout << count + 1;
        cin >> flavor;

        while (flavor <= 0)
        {
            cout << "Jars sold must be greater than or equal to 0.";
            cout << "Re-enter jars sold for last month ";
            cin >> flavor;
            cout << endl;

        }
        getTotal();
        getHigh();
        getLow();
    }
}

void Salsa::getTotal()
{
    total = 0;

    for (count = 0; count < 5; count++)
    {
        total += flavor;

        cout << "Total Sales: " << total << endl;
    }
}

void Salsa::getHigh()
{
    highest = flavor;
    int index = 1;

    for (count = 0; count < 5; count++)
        if (flavor > highest)
        {
        highest = flavor;
        index = count + 1;
        }

    cout << "High Seller: " << flavor << endl;
}

void Salsa::getLow()
{
    lowest = flavor;
    int index = 1;

    for (count = 0; count < 5; count++)
    {
        if (flavor < lowest)
        {
            lowest = flavor;
            index = count + 1;
        }

        cout << "Low Seller: " << flavor << endl;
    }
}

int main()
{
    const int SALS_FLAV = 5;
    string flavor[SALS_FLAV] = { "mild", "medium", "sweet", "hot", "zesty" };

    Salsa sold;

    for (int index = 0; index < SALS_FLAV; index++)
    {
        sold.getSold();
    }
}