标题说全部。错误是
错误1错误LNK2019:未解析的外部符号" private:void __thiscall Salsa :: getTotal(void)" (?getTotal @ Salsa @@ AAEXXZ)在函数&#34中公开; public:void __thiscall Salsa :: getSold(void)" (?getSold @ Salsa @@ QAEXXZ)
错误2错误LNK2019:未解析的外部符号" private:void __thiscall Salsa :: getHigh(void)" (?getHigh @ Salsa @@ AAEXXZ)在函数中引用" public:void __thiscall Salsa :: getSold(void)" (?getSold @ Salsa @@ QAEXXZ)
错误3错误LNK2019:未解析的外部符号" private:void __thiscall Salsa :: getLow(void)" (?getLow @ Salsa @@ AAEXXZ)在函数&#34中公开; public:void __thiscall Salsa :: getSold(void)" (?getSold @ Salsa @@ QAEXXZ)
错误4错误LNK2019:函数___tmainCRTStartup芯片和莎莎类中引用了未解析的外部符号_main
代码如下; .h文件,然后.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
现在是.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();
}
}
}
}
答案 0 :(得分:3)
您的代码存在许多问题:
请研究您的代码与以下代码之间的差异:
#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();
}
}