C++,使用 .h 和 .cpp 文件的类问题,函数'getEstimate'将无法运行
C++, Class issues using .h and .cpp files, function 'getEstimate' will not run
出于某种原因,即使我认为该类是为使用头文件而创建的,也不会转移任何东西。我正在尝试将一些数据发送到一个类中以进行一些简单的数学运算,然后将结果发回。但是,我已经为您提供了代码背后的基础,我只需要在文件之间传输数据即可工作。
这是代码:
-----------------------------------------主要.cpp----------
#include <iostream>
#include <string>
#include "Estimate.h" //incloude class file
using namespace std;
int main() {//open main
int labour = 3, travel = 4, copper = 2, plastic = 1, chrome = 2;//initialise integers
//constructer for class Job - passing through all the variables above.
Estimate Job(labour, travel, copper, plastic, chrome);
//CALL FUNCTION to print invoice
Job.getEstimate();
system("pause");
return 0;
}//close main
--------------------------------------------估计.h------------
class Estimate {//open classs
public:
int labour, travel, copper, plastic, chrome, subTotal;
float total, vat;
Estimate(int, int, int, int, int);
~Estimate();
void getEstimate() {}
};//close estimate
--------------------------估计.cpp-------------------------------
#include <iostream>
#include <string>
#include "Estimate.h"
int labour, travel, copper, plastic, chrome, subTotal;
float total, vat;
//constructor and destructor
Estimate::Estimate(int labour,int travel, int copper, int plastic, int chrome) {
this -> labour = labour;
this -> travel = travel;
this -> copper = copper;
this -> plastic = plastic;
this -> chrome = chrome;
}//constructor
Estimate::~Estimate() {}//destructor
void getEstimate() {
std::cout << "################### Estimate ###################";
system("pause");
}//function
您需要从编译的代码开始。 正如马尔钦所提到的,你需要做#include <iostream>
和#include <string>
现在,在标头中,您将Estimate::getEstimate
定义为空函数{}
。在您的实现中,您定义了一个作用域函数getEstimate
。
将标题中的行更改为:
void getEstimate();
以及您的实现中的行:
void Estimate::getEstimate(){
相关文章:
- 运行同一解决方案的另一个项目的项目
- CMake-按正确顺序将项目与C运行时对象文件链接
- 如何运行位于boost/libs/python/example/tutorial目录中的hello.cpp和Jamfil
- 代码在main()中运行,但在函数中出现错误
- 我在c++代码中生成了一个运行时#3异常
- 如何在linux终端中同时编译和运行c++代码
- 为什么在运行时没有向我们提供有关分段错误的更多信息?
- 如何在运行中期切换GTK CSS style_context
- 如何在MS Visual Studio 2019中运行QT UI
- 如何通过cpp程序运行shell脚本
- IPC使用多个管道和分支进程来运行Python程序
- 删除指向指针的指针是运行时错误吗
- 如何用参数值调用函数(仅在运行时已知)
- 为什么即使使用-cudart-static进行编译,库用户仍然需要链接到cuda运行时
- 是否可以在编译时初始化数组,以便在运行时不会花费时间?
- c++中的指针和运行时错误
- 在C应用程序中运行C++(带有STL)函数
- 运行程序时出现问题
- 控制允许动态运行c++的并发操作数
- C++,使用 .h 和 .cpp 文件的类问题,函数'getEstimate'将无法运行