简单C++中的错误,但无法找出原因
An error in simple C++, but can't figure out why
我有这样的代码1> test.obj:错误LNK2019:"void __cdecl iceCreamDivision(int,double)"(?iceCreamDivision@@YAXHN@Z)외부 기호(참조 위치: _主要的함수)에서 확인하지 못했습니다.1> D:\download\C161\Debug\C161.exe:致命错误LNK1120:1개의 확인할 수 없는 외부 참조입니다.很抱歉,这是韩语,但它说有一个外部符号,错误在第一个void方法上。这段代码直接来自教科书,我想知道为什么它不起作用。
#include <iostream>
using namespace std;
void iceCreamDivision(int number, double totalWeight);
int main()
{
int number;
double totalWeight;
cout << "Enter the number of customers: ";
cin >> number;
cout << "Enter weight of ice cream to divide (in ounces): ";
cin >> totalWeight;
iceCreamDivision(number, totalWeight);
return 0;
}
void iceCreamDivison(int number, double totalWeight)
{
double portion;
if (number == 0)
{
cout << "Cannot divide among zero customers.n";
return;
}
portion = totalWeight/number;
cout << "Each one receives "
<< portion << " ounces of ice cream." << endl;
}
我认为您的代码中存在拼写错误
你申报了
void iceCreamDivision(int number, double totalWeight);
但是你定义了
void iceCreamDivison(int number, double totalWeight)
请注意Division
和Divison
之间的差异。请参阅学习C++也可以帮助您学习英语。
您声明了iceCreamDivision
,但使用拼写错误的名称iceCreamDivison
定义了一个不同的函数。将缺少的i
添加到定义中。
相关文章:
- 警告处理为错误这里有什么问题
- "error: no matching function for call to"构造函数错误
- boost::进程间消息队列引发错误
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- QT在错误的班级中寻找空位
- vector.resize()中的分配错误
- 代码在main()中运行,但在函数中出现错误
- 释放错误后堆使用
- (C++)分析树以计算返回错误值的简单算术表达式
- Project Euler问题4的错误解决方案
- 我的字符计数代码计算错误.为什么
- 从"int*"强制转换为"unsigned int"会丢失精度错误
- 尝试导入pybind-opencv模块时出现libgtk错误
- CMake项目Boost库错误:Boost/config/compiler/gcc.hpp:165:10:致命错误:cs
- 在某些循环内使用vector.push_back时出现分段错误
- MSVC多行宏编译器错误
- 静态数据成员的问题-修复链接错误会导致编译器错误
- 为什么在运行时没有向我们提供有关分段错误的更多信息?
- 错误:未在此范围内声明'reverse'