简体   繁体   English

类“错误标识符未定义”

[英]Class “error identifier is undefined”

I'm assuming this is a small syntax issue for when I remove the class and work in only my cpp file it runs without problems... 我假设这是一个小语法问题,因为当我删除该类并仅在我的cpp文件中工作时,它可以正常运行...

I need to use class which will be called by the main function. 我需要使用主函数将调用的类。 The problem I'm running into is that they are not recoginized in the .cpp file. 我遇到的问题是它们在.cpp文件中没有重新识别。

if it would work better to have array or constants declared in header file let me know as well... 如果在头文件中声明数组或常量会更好,请让我知道...

#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();...

Header 标头

#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);
};`

setFee() is a member function of class RestaurantCheck , so you need an instance of that class in order to call that method. setFee()RestaurantCheck类的成员函数,因此您需要该类的实例才能调用该方法。

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

Once you have fixed that, you will find many, many more errors. 解决此问题后,您会发现很多很多错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM