gpt4 book ai didi

c++ - 错误 LNK2019 : Unresolved External Symbol chips and salsa program

转载 作者:行者123 更新时间:2023-11-30 02:40:47 24 4
gpt4 key购买 nike

标题说明了一切。错误是

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)

错误 2 error LNK2019: 未解析的外部符号“private: void __thiscall Salsa::getHigh(void)” (?getHigh@Salsa@@AAEXXZ) 在函数“public: void __thiscall Salsa::getSold(void)” ( ?getSold@Salsa@@QAEXXZ)

错误 3 error LNK2019: 未解析的外部符号“private: void __thiscall Salsa::getLow(void)” (?getLow@Salsa@@AAEXXZ) 在函数“public: void __thiscall Salsa::getSold(void)” ( ?getSold@Salsa@@QAEXXZ)

错误 4 error LNK2019: 未解析的外部符号 _main 在函数 ___tmainCRTStartup Chips 和 Salsa 类中引用

代码如下; .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();
}
}
}
}

最佳答案

你的代码有很多问题:

  1. 你没有声明函数的返回类型
  2. 您不应该以 ; 结束函数定义
  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();
}
}

关于c++ - 错误 LNK2019 : Unresolved External Symbol chips and salsa program,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28665221/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com