3 文件项目中未定义引用中的 C++ 命名空间
c++ namespaces in a 3 file project undefined reference
我正在阅读斯蒂芬·普拉塔(Stephen Prata C++的入门。我刚刚被介绍到命名空间的概念。我创建了一个简单的三文件项目来实现我的命名空间。我还没有实现很多代码,但足以编译它。但是,我收到以下错误:未定义对"SALES::setSales(SALES::Sales&, double const*, int)"的引用。我想我没有正确声明/包含某些内容。这是我的三个文件。请帮助并提前感谢您阅读本文。
//sales.h
#ifndef SALES_H_
#define SALES_H_
namespace SALES
{
const int QUARTERS = 4;
struct Sales
{
double sales[QUARTERS];
double average;
double max;
double min;
};
// copies the lesser of 4 or n items from the array ar
// to the sales member of s and computes and stores the
// average, maximum, and minimum values of the entered items;
// remaining elements of sales, if any, set to 0
void setSales(Sales & s, const double ar[], int n);
// gathers sales for 4 quarters interactively, stores them
// in the sales member of s and computes and stores the
// average, maximum, and minimum values
void setSales(Sales & s);
// display all information in structure s
void showSales(const Sales & s);
}
#endif
//sales.cpp
#include <iostream>
#include "sales.h"
using namespace std;
// copies the lesser of 4 or n items from the array ar
// to the sales member of s and computes and stores the
// average, maximum, and minimum values of the entered items;
// remaining elements of sales, if any, set to 0
void setSales(SALES::Sales & s, const double ar[], int n)
{
}
// gathers sales for 4 quarters interactively, stores them
// in the sales member of s and computes and stores the
// average, maximum, and minimum values
void setSales(SALES::Sales & s)
{
}
// display all information in structure s
void showSales(const SALES::Sales & s)
{
}
//main.cpp
#include <iostream>
#include "sales.h"
using namespace std;
using namespace SALES;
int main()
{
Sales Bill;
const double Bill_sales[] = {1200.23,1400.01,2357.45,4530.58};
setSales(Bill,Bill_sales,QUARTERS);
Sales Mary;
setSales(Mary);
return 0;
}
呃,尝试向函数添加SALES::
。例如
void SALES::setSales(SALES::Sales & s) { }
相关文章:
- 命名空间中具有.h和.cpp文件的类
- 从父命名空间重载类型
- 在命名空间中定义函数还是限定函数
- C++:对不存在的命名空间使用命名空间指令
- 通过继承类使用来自不同命名空间的运算符
- 使用命名空间时出现多个定义错误
- CUDA内核和数学函数的显式命名空间
- 嵌套的匿名命名空间
- CMakeLists.txt中的命名空间表示法
- 类是C++中的命名空间吗
- 在命名空间中使用全局命名空间中的函数
- 如何使 std::sort 在 std::swap 和我的命名空间的模板化交换之间没有名称冲突?
- '使用命名空间{嵌套在另一个命名空间中的某个命名空间}"
- 是否可以将函数导入命名空间,但不能导出它?
- C++ C++类中的命名空间降级
- 如何使用 soong 命名空间来有条件地编译模块
- 使用 Clang++ 有没有办法将文件作为命名空间等包含?
- 使用 make 编译 MPI,几个命名空间错误,例如"错误:未知类型名称'使用'?
- 如何通过命名空间调用非静态方法
- 在命名空间名称之前加上 :: 是什么意思?