我有多个文件,主要驱动程序在头文件中调用函数,然后转到.cpp文件。但是我得到了关于moneyCout()和选择(数字)的未定义引用:
#include <iostream>
#include<stdlib.h>
#include<fstream>
#include "Menu.h"
#include "Gates.h"
#include "Money.h"
#include "Lot.h"
using namespace std;
void moneyCount();
int main()
{
std::ifstream infile;
infile.open("parking_account.txt");
while(!infile.eof())
{
cin>>TotalBills>>ones>>fives>>tens>>twen>>quar;
}
infile.close();
int number;
cout<<"----------------------------------------------------\n\n"
<<"------------------------------------------\n------------------------------------------------------\n"
<<" Parking Machine Accounts\n"
<<"-------------------------------------------------------------------\n------------------------------------------------------------\n"
<<"Sr. No. : BILL NAME : BILL COUNT : COST(in $)\n"
<<"------------------------------------------------------------------------\n";
moneyCount();
cout<<"Which Gate to enter?\n"
<<"1 Gate A\n"
<<"2 Gate B\n"
<<"3 Gate C\n"
<<"4 Report to file\n"
<<"5 Exit\n"
<<"Gate option(1-3): ";
cin>>number;
choice(number);
}
头文件看起来像
#ifndef MENU_H_INCLUDED
#define MENU_H_INCLUDED
#include "Money.h"
#include "Gates.h"
void choice(int choice);
void menu_2_A(int choice);
void menu_3(int choice);
void costMenu(int cost);
#endif // MENU_H_INCLUDED
此标头的.cpp文件是
#include "Menu.h"
#include "Gates.h"
#include <stdlib.h>
#include <fstream>
#include <iostream>
void choice(int choice)
{
if(choice!=5)
{
if (choice==1)
Gate_A();
if (choice == 2)
Gate_B();
if (choice==3)
Gate_C();
if (choice==4)
{
int x =rand() % 29+1;
std::ofstream ReadMe;
ReadMe.open("Parking_Information.txt");
ReadMe<<"Visitors : "<<visit<<"\n";
ReadMe<<"Total Emergency : "<<x<<"\n";
ReadMe<<"Cash at the end of Today : "<<total_credit;
ReadMe<<"Cash from Machine : "<<totalcred;
}
}
}
void menu_2_A(int choice){
if(choice!=3){
if(choice==1){
park_lot();
}
if(choice==2)
park_lot_dist();
}
}
void menu_3(int choice){
if(choice!=3){
if (choice==1)
costMenu(cost);
if(choice==2)
pay_for_spot(totalcred);
}
}
void costMenu(int cost){
int code;
cash cash;
double total_bills_1= 400;
double total_ones= total_bills_1*cash.ones;
double total_bills_5=300;
double total_fives= total_bills_5*cash.fives;
double total_bills_10= 200;
double total_tens=total_bills_10*cash.tens;
double total_bills_20 = 50;
double total_20=total_bills_20*cash.twentys;
double total_bills_quarters= 500;
double total_quarters=total_bills_quarters*cash.quarters;
int total_number_bills = 5;
double total_credit= total_20+total_fives+total_ones+total_quarters+total_tens;
if((total_bills_10==0)||(total_bills_1==0)||(total_bills_20==0)||(total_bills_5==0))
total_number_bills--;
if(cost<totalcred){
std::cout<<"Please enter Cash.\n-----------------------------------------------------------------------------\n"
<<" Currency Denominations to Choose\n"
<<" Code: Type \n"
<<" 1 : One Dollar \n"
<<" 2 : Five Dollar \n"
<<" 3 : Ten Dollar \n"
<<" 4 : Twenty Dollar \n"
<<" 5 : Quarter \n"
<<"----------------------------------------------------------------------\n"
<<"Enter code to credit ";
std::cin>>code;
if(code==1){
totalcred+=cash.ones;
total_bills_1++;
total_ones++;
total_number_bills++;
}
if(code==2){
totalcred+=cash.fives;
total_fives+=5;
total_bills_5++;
total_number_bills++;
}
if(code==3){
totalcred+=cash.tens;
total_tens+=10;
total_bills_10++;
total_number_bills++;
}
if(code==4){
totalcred+=cash.twentys;
total_20+=20;
total_bills_20++;
total_number_bills++;
}
if(code==5){
totalcred+=cash.quarters;
total_quarters+=0.25;
total_bills_quarters++;
}
}
std::cout<<"\nTotal Credit Availiable :"<<totalcred;
print_updated_list(totalcred);
std::cout<<"\nEnter a valid number below: \n\n"
<<"1. Insert Cash\n"
<<"2. Allot a Parking space\n"
<<"3. Exit\n"
<<"Enter Option:(1-2) ";
int number;
std::cin>>number;
if(number<1||number >3){
std::cout<<"Not Valid number. Enter Valid Number\n"
<<"1. Insert Cash\n"
<<"2. Allot a Parking space\n"
<<"3. Exit\n"
<<"Enter Option:(1-2) ";
}
menu_3(number);
}
这是money.h文件:
#define MONEY_H_INCLUDED
int TotalBills;
int ones,fives,tens,twen,quar;
int cost;
double total_credit;
struct cash{
double ones=1.00;
double fives=5.00;
double tens=10.00;
double twentys=20.00;
double quarters=0.25;
};
double totalcred=0.0;
void moneyCount();
void print_updated_list(double money);
double pay_for_spot(double money);
bool CheckCost_1(); //check to see if less than 50
bool CheckCost_2(); // check to see if less than 25
#endif // MONEY_H_INCLUDED:
这是.cpp: #include&#34; Menu.h&#34; #包括 #include&#34; Money.h&#34; #include&#34; Gates.h&#34;
void moneyCount(){
cash cash;
double total_bills_1= ones;
double total_ones= total_bills_1*cash.ones;
double total_bills_5=fives;
double total_fives= total_bills_5*cash.fives;
double total_bills_10= tens;
double total_tens=total_bills_10*cash.tens;
double total_bills_20 = twen;
double total_20=total_bills_20*cash.twentys;
double total_bills_quarters= quar;
double total_quarters=total_bills_quarters*cash.quarters;
int total_number_bills = TotalBills;
double total_credit= total_20+total_fives+total_ones+total_quarters+total_tens;
if((total_bills_10==0)||(total_bills_1==0)||(total_bills_20==0)||(total_bills_5==0))
total_number_bills--;
std::cout<<" 1 : One Dollar : "<<total_bills_1<<" : "<<total_ones<<"\n"
<<" 2 : Five Dollar : "<<total_bills_5<<" : "<<total_fives<<"\n"
<<" 3 : Ten Dollar : "<<total_bills_10<<" : "<<total_tens<<"\n"
<<" 4 : Twenty Dollar : "<<total_bills_20<<" : "<<total_20<<"\n"
<<" 5 : Quarter : "<<total_bills_quarters<<" : "<<total_quarters<<"\n"
<<"----------------------------------------------------------------------\n"
<<"Number of Bill Types: "<<total_number_bills<<"\n";
total_credit=total_credit+totalcred;
std::cout<<"Total Credit: "<<total_credit<<"\n\n";
}
bool CheckCost_1(){
bool temp=false;
if(max_avai<50)
temp=true;
return temp;
}
bool CheckCost_2(){
bool temp=false;
if(max_avai<25)
temp=true;
return temp;
}
void print_updated_list(double money){
cash cash;
double total_bills_1= 400;
double total_ones= total_bills_1*cash.ones;
double total_bills_5=300;
double total_fives= total_bills_5*cash.fives;
double total_bills_10= 200;
double total_tens=total_bills_10*cash.tens;
double total_bills_20 = 50;
double total_20=total_bills_20*cash.twentys;
double total_bills_quarters= 500;
double total_quarters=total_bills_quarters*cash.quarters;
int total_number_bills = 5;
double total_credit= total_20+total_fives+total_ones+total_quarters+total_tens;
if((total_bills_10==0)||(total_bills_1==0)||(total_bills_20==0)||(total_bills_5==0))
total_number_bills--;
std::cout<<" \n 1 : One Dollar : "<<total_bills_1<<" : "<<total_ones<<"\n"
<<" 2 : Five Dollar : "<<total_bills_5<<" : "<<total_fives<<"\n"
<<" 3 : Ten Dollar : "<<total_bills_10<<" : "<<total_tens<<"\n"
<<" 4 : Twenty Dollar : "<<total_bills_20<<" : "<<total_20<<"\n"
<<" 5 : Quarter : "<<total_bills_quarters<<" : "<<total_quarters<<"\n"
<<"----------------------------------------------------------------------\n"
<<"Number of Bill Types: "<<total_number_bills<<"\n"
<<"Total Credit: "<<total_credit+totalcred<<"\n\n";
}
double pay_for_spot(double money){
cash cash;
double total_bills_1= 400;
double total_ones= total_bills_1*cash.ones;
double total_bills_5=300;
double total_fives= total_bills_5*cash.fives;
double total_bills_10= 200;
double total_tens=total_bills_10*cash.tens;
double total_bills_20 = 50;
double total_20=total_bills_20*cash.twentys;
double total_bills_quarters= 500;
double total_quarters=total_bills_quarters*cash.quarters;
int total_number_bills = 5;
double total_credit= total_20+total_fives+total_ones+total_quarters+total_tens;
if((total_bills_10==0)||(total_bills_1==0)||(total_bills_20==0)||(total_bills_5==0))
total_number_bills--;
double change=0.0;
if((money!=0)&&(money>-1)){
if(money-20>=0){
change+=cash.twentys;
total_20-=20;
total_bills_20--;
}
if(money-10>=0){
change+=cash.tens;
total_tens-=10;
total_bills_10--;
}
if(money-5>=0){
change+=cash.fives;
total_bills_5--;
total_fives-=5;
}
if(money-1>=0){
change+=cash.ones;
total_bills_1--;
total_ones--;
}
if(money-.025>=0){
change+=cash.quarters;
total_bills_quarters--;
total_quarters-=0.25;
}
std::cout<<"\nGate is open your change is $"<<change;
print_updated_list(change);
}
std::cout<<"\nGate is open\n";
int number;
std::cout<<"----------------------------------------------------\n\n"
<<"------------------------------------------\n------------------------------------------------------\n"
<<" Parking Machine Accounts\n"
<<"-------------------------------------------------------------------\n------------------------------------------------------------\n"
<<"Sr. No. : BILL NAME : BILL COUNT : COST(in $)\n"
<<"------------------------------------------------------------------------\n";
moneyCount();
std::cout<<"Which Gate to enter?\n"
<<"1 Gate A\n"
<<"2 Gate B\n"
<<"3 Gate C\n"
<<"4 Report to file\n"
<<"5 Exit\n"
<<"Gate option(1-3): ";
std::cin>>number;
choice(number);
}
gates.h:
#ifndef GATES_H_INCLUDED
#define GATES_H_INCLUDED
#include "Lot.h"
#include "Money.h"
struct park{
int maxi;
int avai;
double cost;
int dist;
};
void Gate_A(); //gate a
void Gate_B(); //gate b
void Gate_C(); // gate c
int visit=0;
int max_park= 290;
int max_avai=176;
#endif // GATES_H_INCLUDED
Gates.cpp
#include "Menu.h"
#include "Gates.h"
#include "Lot.h"
#include "Money.h"
#include <iostream>
void Gate_A(){
int visit=0;
visit++;
park park_A;
park park_B;
park park_C;
park park_D;
park park_E;
park park_F;
park park_G;
park park_H;
park park_I;
park_A.maxi=40;
park_A.avai=27;
park_A.cost=25.00;
park_A.dist=10;
park_B.maxi=20;
park_B.avai=7;
park_B.cost=22.50;
park_B.dist=20;
park_C.maxi=50;
park_C.avai=38;
park_C.cost=20.00;
park_C.dist=30;
park_D.maxi=30;
park_D.avai=11;
park_D.cost=22.5;
park_D.dist=20;
park_E.maxi=55;
park_E.avai=41;
park_E.cost=20.00;
park_E.dist=20;
park_F.maxi=15;
park_F.avai=7;
park_F.cost=17.50;
park_F.dist=40;
park_G.maxi=20;
park_G.avai=13;
park_G.cost=20.00;
park_G.dist=30;
park_H.maxi=33;
park_H.avai=21;
park_H.cost=17.5;
park_H.dist=40;
park_I.maxi=27;
park_I.avai=11;
park_I.cost=15.00;
park_I.dist=50;
park_lot();
if(CheckCost_1()==true){
park_A.cost+=5.75;
park_B.cost+=5.75;
park_C.cost+=5.75;
park_D.cost+=5.75;
park_E.cost+=5.75;
park_F.cost+=5.75;
park_G.cost+=5.75;
park_H.cost+=5.75;
park_I.cost+=5.75;
}
if(CheckCost_2()==true){
park_A.cost+=7.25;
park_B.cost+=7.25;
park_C.cost+=7.25;
park_D.cost+=7.25;
park_E.cost+=7.25;
park_F.cost+=7.25;
park_G.cost+=7.25;
park_H.cost+=7.25;
park_I.cost+=7.25;
}
std::cout<<"-------------------------------------------------------------------\n\n\n"
<<"------------------------------------------------------------------\n"
<<" Gate A : Lot Information\n"
<<"------------------------------------------------------------------\n"
<<" LOT ID : MAX CAPACITY : AVAILIABLE SPOTS : COST(IN $) : DISTANCE\n"
<<"------------------------------------------------------------------\n";
for(char i='A';i<'J';i++){
if(i=='A')
std::cout<<i<<" : "<<park_A.maxi<<" : "<<" "<<park_A.avai<<" : "<<park_A.cost<<" : "<<park_A.dist<<"\n\n";
if(i=='B')
std::cout<<i<<" : "<<park_B.maxi<<" : "<<" "<<park_B.avai<<" : "<<park_B.cost<<" : "<<park_B.dist<<"\n\n";
if(i=='C')
std::cout<<i<<" : "<<park_C.maxi<<" : "<<" "<<park_C.avai<<" : "<<park_C.cost<<" : "<<park_C.dist<<"\n\n";
if(i=='D')
std::cout<<i<<" : "<<park_D.maxi<<" : "<<" "<<park_D.avai<<" : "<<park_D.cost<<" : "<<park_D.dist<<"\n\n";
if(i=='E')
std::cout<<i<<" : "<<park_E.maxi<<" : "<<" "<<park_E.avai<<" : "<<park_E.cost<<" : "<<park_E.dist<<"\n\n";
if(i=='F')
std::cout<<i<<" : "<<park_F.maxi<<" : "<<" "<<park_F.avai<<" : "<<park_F.cost<<" : "<<park_F.dist<<"\n\n";
if(i=='G')
std::cout<<i<<" : "<<park_G.maxi<<" : "<<" "<<park_G.avai<<" : "<<park_G.cost<<" : "<<park_G.dist<<"\n\n";
if(i=='H')
std::cout<<i<<" : "<<park_H.maxi<<" : "<<" "<<park_H.avai<<" : "<<park_H.cost<<" : "<<park_H.dist<<"\n\n";
if(i=='I')
std::cout<<i<<" : "<<park_I.maxi<<" : "<<" "<<park_I.avai<<" : "<<park_I.cost<<" : "<<park_I.dist<<"\n\n";
}
std::cout<<"Max Capacity: "<<max_park<<" Max Available: "<<max_avai<<"\n\n\n\n"<<"Select A Criteria to Allot a parking space :\n"
<<"1. Based on cost-cheapest to allot a parking spot\n"
<<"2. Based on Distance - Closest to stadium\n"
<<"3. Return to main menu\n"
<<"4.Exit\n"
<<"Enter option (1-2) : ";
int num;
std::cin>>num;
menu_2_A(num);
}
void Gate_B(){
visit++;
park park_A;
park park_B;
park park_C;
park park_D;
park park_E;
park park_F;
park park_G;
park park_H;
park park_I;
park_A.maxi=40;
park_A.avai=27;
park_A.cost=25.00;
park_A.dist=30;
park_B.maxi=20;
park_B.avai=7;
park_B.cost=22.50;
park_B.dist=40;
park_C.maxi=50;
park_C.avai=38;
park_C.cost=20.00;
park_C.dist=50;
park_D.maxi=30;
park_D.avai=11;
park_D.cost=22.5;
park_D.dist=20;
park_E.maxi=55;
park_E.avai=41;
park_E.cost=20.00;
park_E.dist=30;
park_F.maxi=15;
park_F.avai=7;
park_F.cost=17.50;
park_F.dist=40;
park_G.maxi=20;
park_G.avai=13;
park_G.cost=20.00;
park_G.dist=10;
park_H.maxi=33;
park_H.avai=21;
park_H.cost=17.5;
park_H.dist=20;
park_I.maxi=27;
park_I.avai=11;
park_I.cost=15.00;
park_I.dist=30;
if(CheckCost_1()==true){
park_A.cost+=5.75;
park_B.cost+=5.75;
park_C.cost+=5.75;
park_D.cost+=5.75;
park_E.cost+=5.75;
park_F.cost+=5.75;
park_G.cost+=5.75;
park_H.cost+=5.75;
park_I.cost+=5.75;
}
if(CheckCost_2()==true){
park_A.cost+=7.25;
park_B.cost+=7.25;
park_C.cost+=7.25;
park_D.cost+=7.25;
park_E.cost+=7.25;
park_F.cost+=7.25;
park_G.cost+=7.25;
park_H.cost+=7.25;
park_I.cost+=7.25;
}
std::cout<<"-------------------------------------------------------------------\n\n\n"
<<"------------------------------------------------------------------\n"
<<" Gate B : Lot Information\n"
<<"------------------------------------------------------------------\n"
<<" LOT ID : MAX CAPACITY : AVAILIABLE SPOTS : COST(IN $) : DISTANCE\n"
<<"------------------------------------------------------------------\n";
for(char i='G';i<'J';i++){
if(i=='G')
std::cout<<i<<" : "<<park_G.maxi<<" : "<<" "<<park_G.avai<<" : "<<park_G.cost<<" : "<<park_G.dist<<"\n\n";
if(i=='H')
std::cout<<i<<" : "<<park_H.maxi<<" : "<<" "<<park_H.avai<<" : "<<park_H.cost<<" : "<<park_H.dist<<"\n\n";
if(i=='I')
std::cout<<i<<" : "<<park_I.maxi<<" : "<<" "<<park_I.avai<<" : "<<park_I.cost<<" : "<<park_I.dist<<"\n\n";
}
for(char i='D';i<'G';i++){
if(i=='D')
std::cout<<i<<" : "<<park_D.maxi<<" : "<<" "<<park_D.avai<<" : "<<park_D.cost<<" : "<<park_D.dist<<"\n\n";
if(i=='E')
std::cout<<i<<" : "<<park_E.maxi<<" : "<<" "<<park_E.avai<<" : "<<park_E.cost<<" : "<<park_E.dist<<"\n\n";
if(i=='F')
std::cout<<i<<" : "<<park_F.maxi<<" : "<<" "<<park_F.avai<<" : "<<park_F.cost<<" : "<<park_F.dist<<"\n\n";
}
for (char i='A';i<'D';i++){
if(i=='A')
std::cout<<i<<" : "<<park_A.maxi<<" : "<<" "<<park_A.avai<<" : "<<park_A.cost<<" : "<<park_A.dist<<"\n\n";
if(i=='B')
std::cout<<i<<" : "<<park_B.maxi<<" : "<<" "<<park_B.avai<<" : "<<park_B.cost<<" : "<<park_B.dist<<"\n\n";
if(i=='C')
std::cout<<i<<" : "<<park_A.maxi<<" : "<<" "<<park_C.avai<<" : "<<park_C.cost<<" : "<<park_C.dist<<"\n\n";
}
std::cout<<"Max Capacity: "<<max_park<<" Max Available: "<<max_avai<<"\n\n\n\n"<<"Select A Criteria to Allot a parking space :\n"
<<"1. Based on cost-cheapest to allot a parking spot\n"
<<"2. Based on Distance - Closest to stadium\n"
<<"3. Return to main menu\n"
<<"4.Exit\n"
<<"Enter option (1-2) : ";
int num;
std::cin>>num;
menu_2_A(num);
}
void Gate_C(){
visit++;
park park_A;
park park_B;
park park_C;
park park_D;
park park_E;
park park_F;
park park_G;
park park_H;
park park_I;
park_A.maxi=40;
park_A.avai=27;
park_A.cost=25.00;
park_A.dist=50;
park_B.maxi=20;
park_B.avai=7;
park_B.cost=22.50;
park_B.dist=40;
park_C.maxi=50;
park_C.avai=38;
park_C.cost=20.00;
park_C.dist=30;
park_D.maxi=30;
park_D.avai=11;
park_D.cost=22.5;
park_D.dist=40;
park_E.maxi=55;
park_E.avai=41;
park_E.cost=20.00;
park_E.dist=30;
park_F.maxi=15;
park_F.avai=7;
park_F.cost=17.50;
park_F.dist=20;
park_G.maxi=20;
park_G.avai=13;
park_G.cost=20.00;
park_G.dist=30;
park_H.maxi=33;
park_H.avai=21;
park_H.cost=17.5;
park_H.dist=20;
park_I.maxi=27;
park_I.avai=11;
park_I.cost=15.00;
park_I.dist=10;
if(CheckCost_1()==true){
park_A.cost+=5.75;
park_B.cost+=5.75;
park_C.cost+=5.75;
park_D.cost+=5.75;
park_E.cost+=5.75;
park_F.cost+=5.75;
park_G.cost+=5.75;
park_H.cost+=5.75;
park_I.cost+=5.75;
}
if(CheckCost_2()==true){
park_A.cost+=7.25;
park_B.cost+=7.25;
park_C.cost+=7.25;
park_D.cost+=7.25;
park_E.cost+=7.25;
park_F.cost+=7.25;
park_G.cost+=7.25;
park_H.cost+=7.25;
park_I.cost+=7.25;
}
std::cout<<"-------------------------------------------------------------------\n\n\n"
<<"------------------------------------------------------------------\n"
<<" Gate C : Lot Information\n"
<<"------------------------------------------------------------------\n"
<<" LOT ID : MAX CAPACITY : AVAILIABLE SPOTS : COST(IN $) : DISTANCE\n"
<<"------------------------------------------------------------------\n";
for(char i='I';i>='A';i--){
if(i=='I')
std::cout<<i<<" : "<<park_I.maxi<<" : "<<" "<<park_I.avai<<" : "<<park_I.cost<<" : "<<park_I.dist<<"\n\n";
if(i=='H')
std::cout<<i<<" : "<<park_H.maxi<<" : "<<" "<<park_H.avai<<" : "<<park_H.cost<<" : "<<park_H.dist<<"\n\n";
if(i=='G')
std::cout<<i<<" : "<<park_G.maxi<<" : "<<" "<<park_G.avai<<" : "<<park_G.cost<<" : "<<park_G.dist<<"\n\n";
if(i=='F')
std::cout<<i<<" : "<<park_F.maxi<<" : "<<" "<<park_F.avai<<" : "<<park_F.cost<<" : "<<park_F.dist<<"\n\n";
if(i=='E')
std::cout<<i<<" : "<<park_E.maxi<<" : "<<" "<<park_E.avai<<" : "<<park_E.cost<<" : "<<park_E.dist<<"\n\n";
if(i=='D')
std::cout<<i<<" : "<<park_D.maxi<<" : "<<" "<<park_D.avai<<" : "<<park_D.cost<<" : "<<park_D.dist<<"\n\n";
if(i=='C')
std::cout<<i<<" : "<<park_C.maxi<<" : "<<" "<<park_C.avai<<" : "<<park_C.cost<<" : "<<park_C.dist<<"\n\n";
if(i=='B')
std::cout<<i<<" : "<<park_B.maxi<<" : "<<" "<<park_B.avai<<" : "<<park_B.cost<<" : "<<park_B.dist<<"\n\n";
if(i=='A')
std::cout<<i<<" : "<<park_A.maxi<<" : "<<" "<<park_A.avai<<" : "<<park_A.cost<<" : "<<park_A.dist<<"\n\n";
}
std::cout<<"Max Capacity: "<<max_park<<" Max Available: "<<max_avai<<"\n\n\n\n"<<"Select A Criteria to Allot a parking space :\n"
<<"1. Based on cost-cheapest to allot a parking spot\n"
<<"2. Based on Distance - Closest to stadium\n"
<<"4.Exit\n"
<<"Enter option (1-2) : ";
int num;
std::cin>>num;
menu_2_A(num);
}
lot.h
#ifndef LOT_H_INCLUDED
#define LOT_H_INCLUDED
#include "Gates.h"
int park_lot();
int park_lot_dist();
#endif // LOT_H_INCLUDED
一旦我解决了这些错误,其他错误应该类似于解决。 提前谢谢。
答案 0 :(得分:1)
&#34;未定义的参考&#34;通过链接器意味着它无法找到这些符号的编译代码。这通常意味着它们没有被定义或定义不正确。让我们深入了解您的具体例子。
对于moneyCount,我没有看到实际定义,只看到声明。
void moneyCount();
这很好,但在某个.cpp文件中,您需要为它提供一个正文。那就是:
void moneyCount() {
// your stuff here
}
对于选择(编号),您已将全局函数定义为:
void choice(int choice){
// some stuff
}
但已将其声明为实例函数
class menu{
public:
void choice(int choice);
// more stuff
}
为此,您应该将您的定义更改为:
void menu::choice(int choice){
// some stuff
}
答案 1 :(得分:0)
第一个问题是:
您正在为moneyCout()函数获取未定义的引用错误,因为它没有存在,因为您没有定义该函数。
请学习如何定义功能。 std :: ofstream自述文件;应该在main(我的偏好)中定义。
请定义moneycount功能。不要初始化它!
向我们展示gate.cpp中可能存在问题的门功能。
请记住在menu.cpp中的每个函数之前都有类和范围运算符,如下所示
void menu::choice(int)
void menu::costMenu(int)
最后一个问题是,你实际上必须创建类对象来引用类中的函数。
menu Menu;
Menu.choice(number);
请更正所有错误。