BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / cpp / #87660同步于 2015/6/22
该镜像源已超过 30 天没有更新,可能在源站已被删除。
CPP机器人发帖

求帮忙看看,无法解析的外部符号?

herbice
2015/6/22镜像同步11 回复
一个头文件,两个源文件,出现如下问题 1>源1.obj : error LNK2019: 无法解析的外部符号 "void __cdecl SALES::setSales(struct SALES::Sales &)" (?setSales@SALES@@YAXAAUSales@1@@Z),该符号在函数 _main 中被引用 1>源1.obj : error LNK2019: 无法解析的外部符号 "void __cdecl SALES::showSales(struct SALES::Sales const &)" (?showSales@SALES@@YAXABUSales@1@@Z),该符号在函数 _main 中被引用 代码如下 sales.h namespace SALES { const int QUARTERS = 4; struct Sales { double sales[QUARTERS]; double average; double max; double min; }; void setSales(Sales&s, const double arr[], int n); void setSales(Sales&s); void showSales(const Sales&s); } list 1: #include <iostream> #include"sales.h" using namespace std; using namespace SALES; void setSales(Sales&s, const double arr[], int n) { double max = arr[0]; double min = arr[0]; double total = 0; double average = 0; for (int i = 0; i < n; i++) { if (arr[i]>max) max = arr[i]; if (arr[i] < min) min = arr[i]; total += arr[i]; } average = total / n; } void setSales(Sales&s) { int i = 0; double total = 0; double temp; double average, max, min; cout << "Enter the sales of quarter 1:"; cin >> temp; max = min = temp; while (i++ < QUARTERS&&cin) { if (max < temp) max = temp; if (min > temp) min = temp; s.sales[i] = temp; total += s.sales[i]; cout << "Enter next sales:"; cin >> temp; } average = total / QUARTERS; } void showSales(const Sales&s) { for (int i = 0; i < QUARTERS; i++) cout << "The sale of QUARTER " << i + 1 << " is :" << s.sales[i] << endl; cout << "The average is :" << s.average << endl; cout << "The max is:" << s.max << endl; cout << "The min is:" << s.min << endl; } list 2: #include <iostream> #include"sales.h" using namespace SALES; using namespace std; void main() { const double arr[QUARTERS] = { 31311, 31313, 46546, 16111 }; Sales sa; setSales(sa); showSales(sa); }
订阅后,新回复会通过你的通知中心匿名送达。
9 条回复
nuanyangyang机器人#1 · 2015/6/22
list1和list2的文件名是什么呢?
herbice机器人#2 · 2015/6/22
我没改,分别是源和源1 【 在 nuanyangyang 的大作中提到: 】 : list1和list2的文件名是什么呢? : 发自「贵邮」
nuanyangyang机器人#3 · 2015/6/22
【 在 herbice 的大作中提到: 】 : 我没改,分别是源和源1 : 发自「贵邮」 全名?“源.c”?还是“源.cpp”?
BTup机器人#4 · 2015/6/22
// temp.h namespace BUPT { void setSite(const char *site); }; // temp.h end // temp.cpp #include "temp.h" /* link error using namespace BUPT; void setSite(const char *site) {} */ /* OK 1 void BUPT::setSite(const char *site) {} */ /* OK 2 namespace BUPT { void setSite(const char *site) {} } */ // temp.cpp end 【 在 herbice 的大作中提到: 】 : 一个头文件,两个源文件,出现如下问题 : 1>源1.obj : error LNK2019: 无法解析的外部符号 "void __cdecl SALES::setSales(struct SALES::Sales &)" (?setSales@SALES@@YAXAAUSales@1@@Z),该符号在函数 _main 中被引用 : 1>源1.obj : error LNK2019: 无法解析的外部符号 "void __cdecl SALES::showSales(struct SALES::Sales const &)" (?showSales@SALES@@YAXABUSales@1@@Z),该符号在函数 _main 中被引用 : ...................
xionger机器人#5 · 2015/6/22
函数的符号生成不是在编译函数体的时候么,函数申明不会生成符号的吧,所以得把函数体放在名字空间空。
xiaobing307机器人#6 · 2015/6/22
ls应该是正解,list 1里面定义的函数,跟sales.h里面的函数声明没有关系,不在一个名字空间
herbice机器人#7 · 2015/6/22
源.cpp呢 【 在 nuanyangyang 的大作中提到: 】 : : 全名?“源.c”?还是“源.cpp”?
herbice机器人#8 · 2015/6/22
明白了,多谢! 【 在 BTup 的大作中提到: 】 : [code=c] : // temp.h : namespace BUPT : ...................
herbice机器人#9 · 2015/6/22
明白了,多谢帮忙哈 【 在 nuanyangyang 的大作中提到: 】 : : 全名?“源.c”?还是“源.cpp”?