2012-12-04 181 views
0

我假設這是因爲當我刪除它運行沒有問題只是我的cpp文件中的類和工作小的語法問題...類「錯誤標識符是未定義」

我需要使用類將被主函數調用。我遇到的問題是它們不能在.cpp文件中識別。

它是否會更好地工作,有數組或常量在頭文件中聲明讓我知道還有......

#include '<iostream>' 
#include "Menu.h" 
using namespace std; 


const double RestaurantCheck::MINTAX=.01, RestaurantCheck::MAXTAX=.12,RestaurantCheck::MINTIP=.05,RestaurantCheck::MAXTIP=.20,RestaurantCheck::DEFAULTTAX=.065,RestaurantCheck::DEFAULTTIP=.15; 

//Error nonstatic data member may not be defiend outside of its class 
RestaurantCheck::MexicanMenu[10].ItemName="Marisco El Sol"; 
RestaurantCheck::MexicanMenu[10].ItemDesc="Mouth watering seafood  appetizer made with shrimp, octopus, scallops, mushrooms, red and green peppers. Garnished with lettuce and avocado."; 
RestaurantCheck::MexicanMenu[10].ItemCost=10.95; 

RestaurantCheck::MexicanMenu[1].ItemName="Taquitos"; 
RestaurantCheck::MexicanMenu[1].ItemDesc="Rolled flour tortilla fried with your choice of chicken, shredded beef or shredded pork. Served over a bed of lettuce with Parmesan, tomatoes, guacamole & sour cream."; 
RestaurantCheck::MexicanMenu[1].ItemCost=7.95; 

      ... 

      RestaurantCheck::MexicanMenu[0].ItemName=" ";//my null set. 
      RestaurantCheck::MexicanMenu[0].ItemDesc=" "; 
      RestaurantCheck::MexicanMenu[0].ItemCost=0; 

void main() 
{ 
    double ITax=0,ITip=0,Subtotal=0,UserTip=0,UserTax=0; 
    bool exit=false; 

    int count=0;//delete me after tests 

    while (exit=false) 
    { 
     cout<<"Please input all tips as floating numbers 1% = .01 and 12% = .12\n"; 
     cout<<"What value do you want to set the tip? "; 
      cin>>UserTip; 
     cout<<endl<<"What value do you want to set the tax? "; 
      cin>>UserTax; 

     setFee(UserTip,UserTax);//error: Identifier is undefined 
     placeOrder();... 

頁眉

#ifndef Menu_H 
#define Menu_H 
#include <iostream> 
#include <iomanip> 
#include <string> 
using namespace std; 


class RestaurantCheck 
{ 
    struct Restaurant 
    { 
     string ItemName; 
     string ItemDesc; 
     double ItemCost; 
    }; 

    static const double MINTAX,MAXTAX,MINTIP,MAXTIP, DEFAULTTAX,DEFAULTTIP; 
    double Subtotal,CTax,TaxAmt,CTip,TipAmt; 
    Restaurant Order[10],MexicanMenu[4]; 

    void presentMenu(Restaurant DispMenu[],int NumOfItems); 

public: 
    double calculateTax(double Subtotal,double CTax); 
    double calculateTip(double Subtotal,double CTip); 
    void setFee(double ,double); 
    double issueCheck(Restaurant Order[],double ITax,double ITip,double Subtotal); 
    void placeOrder(Restaurant Menu[],int Num_Menu,Restaurant IOrder[],int Num_Order); 
    //void setMenu(); 


}; 
void RestaurantCheck::setFee(double UTip,double UTax) 
{ 
    if (UTip>=MINTIP&&UTip<=MAXTIP) 
     CTip=UTip; 
    else 
     CTip=DEFAULTTIP; 

    if (UTax>=MINTAX&&UTax<=MAXTAX) 
     CTax=UTax; 
    else 
     CTax=DEFAULTTAX; 
    //return(true); 
};` 
+2

代碼只是一大堆語法錯誤。那裏沒有可以「固定」的單個錯誤。你需要閱讀一本書來獲得關於如何使用C++類的基本概念,甚至不提及'while(exit = false)'這樣的東西...... – AnT

+0

'#include'''?那裏有什麼撇號? –

+0

我所看到的全部都是void main –

回答

1

setFee()RestaurantCheck類的成員函數,因此您需要該類的實例才能調用該方法。

RestaurantCheck r; 
r.setFee(x,y); 

一旦解決了這個問題,您會發現很多更多的錯誤。

+0

另外,RestaurantCheck :: MexicanMenu不是靜態成員,所以初始化它就像靜態成員'RestaurantCheck :: MexicanMenu [...] = ...'不起作用。這段代碼中有很多錯誤。 –

+0

至於數組和> RestaurantCheck :: MexicanMenu [...] = ...我被告知數組無法在頭文件中聲明。這是我試圖去除它。我需要在哪裏移動陣列?在主要funciton或在標題? – Jamesplowrance

相關問題