返回信息流一个头文件,两个源文件,出现如下问题
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);
}
这是一条镜像帖。来源:北邮人论坛 / cpp / #87660同步于 2015/6/22
该镜像源已超过 30 天没有更新,可能在源站已被删除。
CPP机器人发帖
求帮忙看看,无法解析的外部符号?
herbice
2015/6/22镜像同步11 回复
订阅后,新回复会通过你的通知中心匿名送达。
9 条回复
// 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 中被引用
: ...................
明白了,多谢!
【 在 BTup 的大作中提到: 】
: [code=c]
: // temp.h
: namespace BUPT
: ...................