어떤 이유로 클래스가 헤더 파일의 사용을 위해 올바르게 작성되었다고해도 아무 것도 전송하지 않습니다. 몇 가지 간단한 수학을 수행하기 위해 수업에 데이터를 보내고 그 결과를 다시 보내려고합니다. 그러나 코드에 대한 기초를 제공 했으므로 작업 할 파일간에 데이터를 전송해야합니다.C++, .h 및 .cpp 파일을 사용하는 클래스 문제, 'getEstimate'함수가 실행되지 않음
코드는 다음과 같습니다.
------------------------------------- ---- main.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
-------------------------- ------------------ Estimate.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
---------- ---------------- 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>'에'< '가 빠져있는 것처럼 보입니다. – Marcin
그리고 헤더의'getEstimate' 선언의 끝에서'{}'를';'로 대체하십시오. 이것은 비어있는 정의입니다. 당신은 cpp에 정의를 원한다. 또한, cpp에는'Estimate :: getEstimate'이 필요합니다. – sje397
다음 내용을 반드시 읽어보십시오. http://stackoverflow.com/help/mcve – Rook