c++ 函数定义不声明参数

c++ Function Definition does not declare parameters

本文关键字:声明 参数 定义 函数 c++      更新时间:2023-10-16

我在C++项目中遇到编译错误。在我朋友的计算机上,我没有收到任何错误,但在我计算机上,我得到以下信息:

129 - "Function Definition does not declare parameters "线

137 - "'seats' was not declared in this scope"线

我在 Windows 7 上运行代码::块 10.05。

这是我的代码(行号由注释指示):

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

class Plane
{
public:
    int viewSeat(int sNum) {
        if (seats[sNum].isFree()) {
            return 0;
        } else {
            //cout << "Debug (Plane::viewSeat(sNum) called)";
            string seatMess = "";
            switch (seats[sNum].getState()) {
                case 1:
                    seatMess = " is reserved for ";
                    break;
                case 2:
                    seatMess = " has been checked in by ";
                    break;
            }
            cout << "(X) Seat ";
            cout << seats[sNum].getCode();
            cout << seatMess;
            cout << seats[sNum].getFName() << " " << seats[sNum].getLName() << "n";
            return 1;
        }
    }

    void viewAll() {
        for (int x = 0; x < numOfSeats; x++) {
            if ((seats[x].getState() == 0)) {
                cout << "Seat " << seats[x].getCode() << " is freen";
            } else {
                viewSeat(x);
            }
        }
    }
    void viewFree() {
        int freeSeats = 0;
        for (int x = 0; x < numOfSeats; x++) {
            if ((seats[x].getState() == 0)) {
                cout << "Seat " << seats[x].getCode() << " is freen";
                freeSeats++;
            }
        }
        cout << "Found " << freeSeats << " free seatsn";
    }
    void freeSeat(int sNum) {
        seats[sNum].emptySeat();
    }
    string getCode(int sNum) {
        return seats[sNum].getCode();
    }
    int reserveSeat(int sNum, string fName, string lName, int age, int cType, string business = "") {
        if (seats[sNum].isFree()) {
            seats[sNum].setFName(fName);
            seats[sNum].setLName(lName);
            seats[sNum].setAge(age);
            seats[sNum].setType(cType);
            seats[sNum].setState(1);
            seats[sNum].setBusiness(business);
            return 1;
        } else {
            return 0;
        }
    }
    int checkSeat(string lName, string seatCode) {
        int found = 0;
        for (int x = 0; x < (sizeof(seats) / sizeof(Seat)); x++) {
            if ((seats[x].getCode() == seatCode) && (seats[x].getLName() == lName)) {
                found = 1;
                seats[x].setState(2);
                return 1;
            }
        }
        return 0;
    }
    int calcTake() {
        int seatPrice = 5;
        int totalTake, totalSeats = 0, totalWestern = 0, totalBusiness = 0, totalStandard = 0;
        for (int x = 0; x < numOfSeats; x++) {
            if ((seats[x].getState() != 0)) {
                int cType = seats[x].getType();
                int thisSeat;
                if (cType == 1) {
                    // discount for western`
                    thisSeat = 0.75 * seatPrice;
                    totalWestern++;
                } else if (cType == 2) {
                    // discount for business
                    thisSeat = 0.8 * seatPrice;
                    totalBusiness++;
                } else {
                    thisSeat = 0.95 * seatPrice;
                    totalStandard++;
                }
                totalTake = totalTake + thisSeat;
                totalSeats++;
            }
        }

        return totalTake;
    }
    int isFree(int sNum) {
        if (seats[sNum].isFree()) {
            return 1;
        } else {
            return 0;
        }
    }

private:
    // Line 129 ("Function Definition does not declare parameters"):
    Seat seats[32] { {"1A"}, {"1B"}, {"1C"}, {"1D"},
        {"2A"}, {"2B"}, {"2C"}, {"2D"},
        {"3A"}, {"3B"}, {"3C"}, {"3D"},
        {"4A"}, {"4B"}, {"4C"}, {"4D"},
        {"5A"}, {"5B"}, {"5C"}, {"5D"},
        {"6A"}, {"6B"}, {"6C"}, {"6D"},
        {"7A"}, {"7B"}, {"7C"}, {"7D"},
        {"8A"}, {"8B"}, {"8C"}, {"8D"}
    };
    // Line 137 ("'seats' was not declared in this scope"):
    int numOfSeats = sizeof(seats) / sizeof(Seat);
};

我想你错过了=

 Seat seats[32] = { {"1A"}, {"1B"}, {"1C"}, {"1D"},..