2012-12-04 225 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

相关问题